Game Development Reference
In-Depth Information
Reference, and reread the reference each time you come across new or unfamiliar topics. You'll find
they become clearer as you continue building your overall knowledge base.
Awesome—you've added a script to the game scene that accepts user interaction and provides user
control over movement of the Main Camera game object.
Let's look closer at how a script affects the game object's behavior.
A class is very simply a collection of variables and functions. In UnityScript each script is a class,
and the script name is the class name. The order of functions within the script isn't important, but
then how does Unity know which functions to run?
Note For the sake of organization if you use a consistent order in your scripts for commonly-used functions,
it is much easier to work with especially when you go back to it later.
This is part of the under-the-hood function of the game engine. When you enter Play mode, a
specific sequence of events occurs, driven by the Unity engine. To get the behavior in your game
that you are looking for, it is as important to understand where your code belongs in relation to these
events as it is to know what code to write.
Getting the Game Started
When you launch a game, typically one of the first things you see is a loading screen. Depending on
the game it might appear before or after a title screen. In either case, behind that loading screen and
status bar the game engine is busily preparing the game to be played. As the game objects and their
scripts are instantiated, a specific sequence of function calls are made that you can utilize within
your scripts to control your game objects' behaviors.
Awake
When the game is started, first of all the game objects are instantiated , or created. After a game
object is instantiated, the script instance is loaded . The Awake() function is called this one time
during the script's lifetime as the script instance is loaded in order to get things set for gameplay
such as initializing the script's variables.
The order in which the game objects' Awake() function is called is random, so you would not want to
use the Awake() function for passing information from one object to another as the receiving object
might not be ready yet.
Start
Start() is also called only once, when the script is enabled . This only takes place after Awake() has
been called on every object in the scene.
 
 
Search WWH ::




Custom Search