Game Development Reference
In-Depth Information
Classified Intel
If we take a look at New3PSController.js , we will see that we used the
BroadcastMessage("Reload"); and BroadcastMessage("Fire", shotAnimation.
length); . Both of these funcions basically call all the funcions named Reload or Fire ,
in this game object or any of its children. This is a great way to make our script and object
more organized.
Performance wise, BroadcastMessage() is slower than a
funcion call because it iterates through all possible target objects,
inds matches of the desired funcion, and executes them. Therefore,
it won't cause a huge increase in performance if we don't have a large
number of funcion calls.
We can have diferent scripts atached to the children of this object and trigger at the same
ime. For example, BroadcastMessage("Fire", shotAnimation.length) will call
the Fire(var f:float) funcion in each component atached to the object (irrespecive
of whether we're calling it on the Component or the GameObject ). So, when the user hits
ire, we will have the rocket shot at the same ime with the smoke coming out from the
launcher without having to code everything in one big script. We can see more details from
the following links:
http://unity3d.com/support/documentation/ScriptReference/Component.
BroadcastMessage.html .
http://unity3d.com/support/documentation/ScriptReference/GameObject.
BroadcastMessage.html .
Next, we will take a look at the waitForShot() funcion, we will see that we use _
animation.PlayQueued(shotAnimation.name, QueueMode.PlayNow); instead of
the CrossFade() funcion. This is because we want to play the shot animaion as soon as
the player presses fire. The PlayQueued() funcion will help us to fade between the same
animaion smoothly. We can see further details of this funcion from the following website:
http://unity3d.com/support/documentation/ScriptReference/Animation.
PlayQueued.html .
Creating the rockets and particles
In this secion, we will coninue creaing the rocket prefab, which will shoot out from the
launcher. We will also create the trail smoke the follows this rocket, the smoke from the
launcher barrel, and the explosion when the rocket hits something.
 
Search WWH ::




Custom Search