Game Development Reference
In-Depth Information
Step 13: Play and test. This will be a little weird because the character will
be looking around wildly as the mouse moves to get over the buttons.
Step 14: Further refine by telling the texture to not only swap out, but to
turn up its Alpha value so it becomes more opaque. And then tell it to turn
it back down when the mouse exits:
var buttonReg : Texture2D;
var buttonOver : Texture2D;
function OnMouseOver(){
guiTexture.texture = buttonOver;
guiTexture.color = Color (.5,.5,.5,.5);
}
function OnMouseExit(){
guiTexture.texture = buttonReg;
guiTexture.color = Color (.5,.5,.5,.25);
}
Step 15: Save. Return to Unity and fix any syntax issues.
Step 16: Ensure the engine state is ready. Open the AC_ToolFunctionalityScript.
Toward the top of the script (in all the variable declarations) there should
be several Booleans. Change all the Booleans to private variables (we don't
want to control them in Unity's editor, we want the buttons to do it), and
create a new variable for flashlightActive. Your variables should look like this:
private var flashlightActive : boolean;
private var pistolActive : boolean;
private var empActive : boolean;
private var empGhostActive : boolean;
Why?
The only ones that really matter to us for the inventory system
are flashlightActive, pistolActive, and empActive. Remember that
empGhostActive is part of the EMP mechanism.
Step 17: Save AC_ToolFunctionalityScript.
Refresher on Interscript Communication
Remember that in the AC_ToolFunctionality script, we are calling functions
within the script, and we do so by just calling out the name of the function
(AddHighlight(hitObj), for instance, says, “go fire the function AddHighlight
with the parameter hitObj. And this function is included here in this
script”). However, we can fire functions that exist in other scripts as well.
We just need to tell Unity where that script is; particularly, what object it's
attached to.
We do this with the following format:
 
Search WWH ::




Custom Search