Game Development Reference
In-Depth Information
if (toolFunctionality.pistolActive){
StorePistol();
} else {
ReadyPistol();
}
}
Why?
So when the InventoryButton_Pistol is clicked, this script goes out to
the toolFunctionality script and turns off the Boolean empActive. Then,
it checks to see if flashlightActive is true, and if it is, it runs the function
StoreFlashlight (which sets flashlightActive to false). Then, it checks if
pistolActive is true. If it is, it fires the StorePistol function (which sets
pistolActive to false). If pistolActive is not true, it fires the ReadyPistol
function (which sets pistolActive to true).
Step 29: Create an identical structure for the flashlight. Make sure it's set
up to work as a toggle as well:
if (name == "InventoryButton_Flashlight"){
toolFunctionality.empActive = false;
if (toolFunctionality.pistolActive){
StorePistol();
}
if (toolFunctionality.flashlightActive){
StoreFlashlight();
} else {
ReadyFlashlight();
}
}
Step 30: Get Unity to wait around for just a bit while animations play
and mouse clicks are registered. Add the following yield WaitForSeconds
commands:
function OnMouseDown (){
var toolFunctionality = mainCamera.GetComponent
("AC_ToolFunctionalityScript");
if (name == "InventoryButton_EMP"){
if (toolFunctionality.flashlightActive){
StoreFlashlight();
}
if (toolFunctionality.pistolActive){
StorePistol();
}
yield WaitForSeconds (.75);
toolFunctionality.empActive = true;
}
if (name == "InventoryButton_Pistol"){
 
Search WWH ::




Custom Search