Game Development Reference
In-Depth Information
Classified Intel
In this secion, we used the
Instantiate()
funcion to clone a new game object from the
prefab
object in the
Project
view. The
Instantiate()
funcion takes three parameters,
which are the original
Object
,
Position (Vector3)
, and
Rotation (Quaternion)
. The
Position
and
Rotation
objects are the transform parameters at the start posiion of the object, which
will be created in the scene. The
Instantiate()
funcion can take any kind of object and
the result can also be returned to any kind of objects. We can also see more examples and
details from the Unity document at:
http://unity3d.com/support/documentation/ScriptReference/Object.
Instantiate.html
http://unity3d.com/support/documentation/Manual/Instantiating%20
Prefabs.html
.
Next, we will talk about the
Invoke()
funcion, which we used to call the funcion ater the
ime we have set in seconds. If some of you have experience with
Actionscript
, this funcion
is very similar to the
setTimeOut()
funcion. We can also use
InvokeRepeating()
to call the method similar to the
Invoke()
funcion, but this funcion will repeat calling
that funcion every ime we set in seconds. We can see more details about the
Invoke()
funcion from the Unity document at:
http://unity3d.com/support/documentation/ScriptReference/
MonoBehaviour.Invoke.html
.
For the
InvokeRepeating()
funcion, refer to the following website:
http://unity3d.com/support/documentation/ScriptReference/
MonoBehaviour.InvokeRepeating.html
.
Finally, let's talk about the posiion of the rocket that launches from the same posiion of
the scope target UI. This is a bit tricky because we want the player to be able to aim and
shoot the rocket exactly to the same posiion that he/she is aiming at. So, we add the
RocketLauncher
object as a child of the
Main Camera
because we want it to move or
rotate with the user view, which is the
Main Camera
. Then, we add the scope target UI at
the center of the screen because it is easier for the player to aim than than if we put it on
one side. So, we set up the posiions
X
and
Y
of
RocketLauncher
object to
0
because it
is the same posiion to the
Main Camera
and if we get the posiion of the
Main Camera
to the screen posiion it will be the center of the screen. Then, we set up the
Z
posiion
of
RocketLauncher
object to
2
because it is the same depth as our character weapon
graphics. This is to make the rocket not too close to the camera. We can also see it from the
following diagram: