Game Development Reference
In-Depth Information
if (toolFunctionality.flashlightActive){
StoreFlashlight();
}
yield WaitForSeconds (.75);
if (toolFunctionality.pistolActive){
StorePistol();
} else {
ReadyPistol();
}
}
if (name == "InventoryButton_Flashlight"){
toolFunctionality.empActive = false;
if (toolFunctionality.pistolActive){
StorePistol();
}
yield WaitForSeconds (.75);
if (toolFunctionality.flashlightActive){
StoreFlashlight();
} else {
ReadyFlashlight();
}
}
}
Why?
Currently, in one frame, this script is doing things like enabling the
empActive (which then means that the click is also registered as
placing the actual mine). Of other problems, in one frame we're
doing things like telling Unity to fire the StorePistol function (which
plays an animation backward) and telling it to play ReadyFlashlight.
These commands are happening right after each other, which means
it abandons playing the first animation and just plays the second. By
providing a few yields, we allow the animations to play before firing
the next batch. This also ensures that the mouse click that Unity
registers when the button is clicked does not register as firing the
gun or placing the mine.
Step 31: Save and return to Unity. Don't try running the game yet, we've
got some other things to do, but do check to make sure there are no
syntax problems.
Hiding and Showing Weapons
Currently, the pistol is likely active, but the flashlight is not. This means that
even though the animations for the arm are firing, Aegis is always holding the
gun—and holding it very strangely when he's supposed to be holding the
flashlight.
 
Search WWH ::




Custom Search