Game Development Reference
In-Depth Information
Biography, drag the DataPanel_Biography GUITexture object from the
Hierarchy to its input field. Do the same for Data Panel Mission. Repeat this
process for each of the buttons.
Why?
Now each button knows what the DataPanels are. Now it's time to define
what to do with them.
Step 33: Open OpenSceneButtonsScript (or just swap to UniSciTE or
Unitron where the script is likely still open).
Step 34: Add the following block (italicized):
var dataPanelBiography : GameObject;
var dataPanelMission : GameObject;
function OnMouseEnter () {
guiTexture.color = Color (1,1,1);
}
function OnMouseExit (){
guiTexture.color = Color (.2,.2,.2);
}
function OnMouseDown(){
if (name == “Button_Bio”){
dataPanelBiography.guiTexture.enabled = true;
dataPanelMission.guiTexture.enabled = false;
}
}
Why?
The first part of the script (function OnMouseDown ()) should be
pretty clear now. We're telling Unity that when the mouse is clicked
on this object do the things within {}. Then comes the powerful part;
when the object (what this script is attached to) checks to see if the
name is “Button_Bio” (if name == “Button_Bio”, and it is important
that the name typed here matches exactly the name listed in the
Hierarchy). If it is, turn on the dataPanelBiography's GUITexture
component (dataPanelBiography.guitTexture.enabled=true) and turn
off the dataPanelMission component (dataPanelBiography.guiTexture.
enabled=false).
If the name of the object clicked is not “Button_Bio” it moves on to the
next block of code.
Tips and Tricks
Enabled vs Active: Generally GameObjects are activated (this
.active = true), while components are enabled (this.component
.enabled = true).
Search WWH ::




Custom Search