Game Development Reference
In-Depth Information
This Smoke script will be added to the Fluffy Smoke object that we just created.
In this funcion, we use the Invoke() funcion, which will tell the script to call the
KillObject() funcion ater the timeout (0.5 seconds).
5. Next, we will drag our Smoke script which we created to this Fluffy Smoke object
(this will break the prefab again, so click on continue to break the prefab).
6. Now, create a new prefab for our new Fluffy Smoke object by going to Assets |
Create | Prefab and name it ShotSmoke . Then, drag the Fluffy Smoke object in
the Hierarchy view to the ShotSmoke prefab in the Project view. Finally, we remove
the Fluffy Smoke object in the Hierarchy view by right-clicking on the Fluffy
Smoke object in the Hierarchy view and choosing Delete ; now we have the new
ShotSmoke prefab.
7. Create the rocket prefab by dragging the rocket ( FBX ) model in the Project view,
inside ( Chapter5/Rocket ) to the Hierarchy view.
8. Click on the rocket model and go to its Inspector view to remove the Animation by
right-clicking and choosing Remove Component . (This will bring up the losing prefab
pop-up, so we just click Continue to break the prefab.)
In Unity, every imported FBX model will have the
Animation component atached to itself automaically,
but for our rocket, we don't need to use the Animation
component, so we removed it from our model.
9. We will now create the Rocket script, so go to Assets | Create | Javascript and
name it Rocket ; double-click on it to open MonoDevelop . Then, go to the script
and replace the code as follows:
@script RequireComponent(ConstantForce)
public var timeOut : float = 3.0; // Destroy after 3.0 seconds.
public var explosionParticle : GameObject;
// Use this for initialization
public function Start () : void {
Invoke("KillObject", timeOut);
}
public function OnCollisionEnter (others : Collision) : void {
//Create the explosion on the first impact point of the rocket
and collider
var contactPoint : ContactPoint = others.contacts[0];
 
Search WWH ::




Custom Search