Game Development Reference
In-Depth Information
Now, we can click Play to see the result. We should be able to walk around by pressing the
arrow, W , A , S , D , or Space key to jump, move the mouse to rotate around, press E to aim,
press R to reload the rocket, and click on the let mouse buton to ire the rocket. However,
we won't be able to see the number of bullets right now, because we don't have any UI set
up to show the number yet. So, in the next step, we will create a bullet count UI by using
GUITexture and OnGUI() .
Objective Complete - Mini Debriefing
In this secion, we just created the rocket and paricle efect that will appear when the player
presses ire. It seems like a lot to do in one secion, but it was worth it.
First, in the Rocket script, we used @script RequireComponent(ConstantForce) to
tell the script to require the ConstantForce for this rocket; this will tell Unity to basically add
the ConstantForce automaically when we add this script to the object.
ConstantForce is one of the Physics components in Unity that will add a
constant force to the RigidBody object (the ConstantForce works with the
RigidBody components, so when we add the ConstantForce to our object,
Unity will automaically add the RigidBody as well), which will contain the
properies that we can use to control the rocket movement. For more details
please have a look at the following website:
http://unity3d.com/support/documentation/Components/
class-ConstantForce.html .
Next, we have the timeout and explosion parameters. We then have the Invoke()
funcion calling the KillObject() funcion ater the timeout (3.0 seconds). Then, we
check for the collision object—if the rocket hits something, it will get to the posiion where
the collision occurs, add the explosion object to that posiion, and then the rocket object will
kill itself.
The KillObject() funcion basically stops the paricle emiter, makes sure that the paricle
will destroy itself by seing the autodestruct parameter to true , detaches the paricle,
and destroys the game object itself.
Now, we create the script for the rocket and smoke paricle. Then, we use the built-in paricle
package and adapt to the way we want for smoke and smoke trial. Finally, we put everything
together and get the result as expected.
 
Search WWH ::




Custom Search