Game Development Reference
In-Depth Information
We are now ready to code the behavior in our script. In the cut-scenes of some video games,
the camera moves around slowly and shows the player the scene from different angles.
Why don't we try something like this? Assuming that we want the camera to keep moving
upwards slowly, we need to move it by constant speed in the positive direction of the y
axis. Additionally, we can add a variable that controls movement speed. Listing 2 illustrates
necessary code for camera movement. Double clicking a script file loads the default script
editor ( MonoDevelop in our case) and opens the script for you to edit the code.
Listing 2: Camera moving script
It is a good idea now to describe the mechanism that Unity uses to run the scripts. When the
game starts, Unity calls Start() function from all active scripts in the scene. By doing this,
Unity makes sure that all scripts are initialized and ready to enter the game update loop. In
this loop, frames are constructed and rendered through various steps. These steps include
reading user input, moving and animating objects, running the physics simulation and Ar-
tificial Intelligence (AI) algorithms, executing the game logic, and rendering the frame. In
order to have an acceptable play experience for the player, at least 25 to 30 frames must be
rendered every second. In each iteration of this loop, Unity passes through all active scripts
in the scene and calls Update() function from them. This procedure continues as long as the
game is running.
Search WWH ::




Custom Search