Game Development Reference
In-Depth Information
Figure 5-34. The script's new additions
9.
Click Play.
The messages correctly report the parent object of the components used by the variables (Figure 5-35 ).
Figure 5-35. The message reporting the camera component's parent, Main Camera, and the specified VariablesTest script
component's parent, Walkway
In using GetComponent , you may occasionally come across Unity functions that do not have generic
counterparts yet. The nongeneric variant, with typeof([ the component name here ]) may be
required. A search of the Unity Manual for “Generic Functions” will give you a C# example of the
syntax. In this form, your GetComponent line would look as follows:
myCustomScript = (VariablesTest) GameObject.Find("Walkway").GetComponent(typeof(VariablesTest));
There are plenty of other things you can do in the Start function, but as with the tests you have just
performed, most have to do with identification and initialization.
Using the Update Function
The Update function, also included in the scripting template, is called at least every frame. This is
where you will manage things like generic input—a key press, for example. It is also where you can
set things to happen over a period of time. As you may expect, code in this function should be kept
as efficient as possible.
 
Search WWH ::




Custom Search