Game Development Reference
In-Depth Information
}
if (name == “Button_Begin”){
Application.LoadLevel (“Scene-EntryWay”);
}
}
Why?
Lastly, if the object is named “Button_Begin” it will load the level or go
to the level Scene-EntryWay, which is the Unity scene created in earlier
tutorials.
Step 37: Save and return to Unity. Adjust any errors with syntax; this can
take a little while and some careful scrutiny, but remember Unity won't
run until the syntax is acceptable.
Step 38: Deactivate DataPanel_Biography and DataPanel_Mission
GameObjects' GUITextures. One at a time, select the GameObject in the
Hierarchy, then in the Inspector click off GUITexture component. This will
make these DataPanels disappear from the Game view.
Why?
When the level starts, both of the DataPanels should be off and only be
visible when their corresponding button is clicked.
Step 39: Play. Test the game. The mission and bio buttons should both
work and show the corresponding DataPanels when clicked. The begin
button assuredly will not work yet—we'll fix that in a bit.
Further Optimization
The script works (well mostly, but we'll fix that Begin button in a bit). However,
it's fairly clumsy to have to define manually the DataPanels for each pesky
button. It would sure be nice if Unity would do that for us.
function Start and function Awake
So far we have used functions that are activated when a specific user-defined
event occurs (the player moves the mouse over an object, leaves the object,
or clicks the object). We can also write functions that happen when the game
begins on an object (containing a script) that is activated.
function Awake is a function that is called when the game launches. Well,
in theory it fires after all the objects in the scene are loaded, but before the
player can interact with the rest of the game. This means certain settings can
be set here, or variables defined.
A close cousin to function Awake is function Start . The difference is that
function Start fires after function Awake, and will fire only if the object is
active. This means an object could be turned off and the game started, and
Search WWH ::




Custom Search