Game Development Reference
In-Depth Information
There are a few ways to ask Unity to check if (this is true). One way is to check
if two values equal each other. To check this, JavaScript uses two equals signs
(==). One equal sign is used to define a value, two checks for equivalency. So
(with some more pseudo code):
if (pieceofClothing == “hat”){
PutOnHead
}
This checks if the piece of clothing is a hat. If it is (==“hat”), then go ahead and
fire the command Put On Head.
What we're going to do there is when a button is clicked, Unity is going to
check to see if the name of the object matches “Button_Bio” for instance, and
then if it does, activate the DataPanel_Biography GameObject.
But before we do that, we need to create some variables to hold the
DataPanel objects. Then these variables can be used in the code to turn the
DataPanels on and off.
Step 30: Open OpenSceneButtonsScript. At the top of the script make the
following variable declarations (the entire code is included here with the
additions in italics):
var dataPanelBiography : GameObject;
var dataPanelMission : GameObject;
function OnMouseEnter () {
guiTexture.color = Color (1,1,1);
}
function OnMouseExit (){
guiTexture.color = Color (.2,.2,.2);
}
Why?
We know it's a variable declaration because it begins with var. Then we
name the variable (dataPanelBiography and dataPanelMission) and
define its type (tell Unity what kind of information will be housed in this
variable—in this case a GameObject). This means anywhere else in the
code we can do things to, or get information from, these new variables.
Of course, we aren't doing anything with them and we have not linked
them to our GUI Textures quite yet, but we will.
Step 31: Save and return to Unity.
Step 32: Assign the contents of the variables. Select any of the three
buttons where this script is attached and look for the Button Highlight
(Script) component that will show up in the Inspector. Notice that there
are two new input fields there (Data Panel Biography and Data Panel
Mission). These are the variables we just declared. Both should read None
(Game Object). To assign a GameObject to this variable, just drag the
 
Search WWH ::




Custom Search