Game Development Reference
In-Depth Information
In line 15, we need to move the object upwards with specific distance every frame, and
we need to compute this distance. As we know from physics, the speed of an object equals
the distance the object moves in the time unit. Therefore, we need to multiply the speed
by the time unit to compute the distance we need to move the object with. But how to get
this time? Since translation is performed once every frame, the time we need to know is
the time passed since the rendering of the previous frame (i.e. since the last time the object
moved). This value is given to us by Unity in the variable Time.deltaTime . So, when we
multiply this value by the movement speed, we get the distance we need to move the object
with. All you have to do now is to save the script and start the game to see the result.
One interesting feature of Unity is the ability to modify the default values of the public
variables directly from the inspector, so we do not have to change the code and recompile
it after every modification. Illustration 13 shows how do public variables appear in the
inspector. You may try to change the speed to a negative value and see the result you ex-
pect.
Search WWH ::




Custom Search