Game Development Reference
In-Depth Information
(which is what Update does) but rather fires only when the mouse is over
an object—in this case a GUITexture. So delete the suggested script start.
Step 24: Enter the following script:
function OnMouseEnter () {
guiTexture.color = Color (1,1,1);
}
Why?
OnMouseEnter is a built-in function Unity knows and includes. Basically,
when using it Unity is saying, “when the mouse enters the space of
the object this script is attached to, do the commands within the {}.”
In this case, the commands between the {} is to define the color of the
GUITexture to be RGB = 1 (the three values there (1,1,1) are (R,G,B). So
when this script is attached to one of the GUITextures that are buttons,
when the mouse rolls over it, it will pop up white.
Step 25: Save, and go back into Unity. Check the Console for errors
(usually a forgotten “;” or a missing “)” or “}”). If the Console remains quiet,
all's well with the syntax of the script.
Tips and Tricks
If there are problems with the script's syntax, Unity will point out which
line numbers they are on. Annoyingly, UniSciTE is set up so that the line
numbers don't appear by default. To display them, in UniSciTE, choose
View>Line Numbers. Having access to that makes fixing syntax problems
much, much faster.
Step 26: Apply the script. Drag the OpenSceneButtonsScript script from
the Project panel onto the Button_Mission GameObject in the Hierarchy.
Also drag the script to Button_Bio and Button_Begin.
Warnings and Pitfalls
Before Unity will let you
run a game, all the script
errors must be fixed.
If (for some reason),
you have scripts that
were brought in from a
unitypackage that you
aren't using and they're
throwing errors, you
can just delete, or even
better, copy them to
some place outside of
the Unity assets folder
and then delete them
from the Unity project
(be sure to delete from
within Unity).
Tips and Tricks
Note that what's happening here is we are using the same script on
multiple objects. Reusing scripts like this can be a tremendous time saver.
Why?
Right now we are draping individual objects with scripts that affect
those objects' direction. It's worthwhile to point out that the dot syntax
is in full effect here. In the script, the command reads guiTexture.color,
but what this really means is this.guiTexture.color. The “this” means this
GameObject the script is attached to. So it's looking at the GameObject
the script is attached to, then down to the guiTexture component, and
the color attribute of that component.
Search WWH ::




Custom Search