Game Development Reference
In-Depth Information
Step 25: Look to the OnMouseDown function. Look at the new
functions when buttons are pressed. In each place where the line
toolFunctionality.pistolActive = false ; appears, we need to
replace it with the block of code:
if (toolFunctionality.pistolActive){
StorePistol();
}
Why?
Instead of just turning pistolActive to false (which would leave the arms
showing the pistol even though it couldn't be fired), we're telling Unity, “if
in the component toolFunctionality, the state of pistolActive is true, run
the function StorePistol.” Then in the StorePistol function the pistolActive
Boolean will be shut off in toolFunctionality.
Step 26: Continuing in the OnMouseDown function, replace everywhere
that the script says toolFunctionality.flashlightActive = false;
with the following block of code:
if (toolFunctionality.flashlightActive){
StoreFlashlight();
}
Step 27: In the block of code that is checking to see if the button pressed is
InventoryButton_Pistol, remove the toolFunctionality.pistolActive
= true; line. Remember we are now turning that on in the ReadyPistol
function. Instead, we just need to tell the script to go and fire the ReadyPistol,
which will switch the Boolean on for us. This will make sure the gun gets
pulled out before we can fire it. So the block of code that deals with the
InventoryButton_Pistol should look like this, with new code in italics:
if (name == "InventoryButton_Pistol"){
toolFunctionality.empActive = false;
if (toolFunctionality.flashlightActive){
StoreFlashlight();
}
ReadyPistol();
}
Step 28: Further expand this chunk of code to be a toggle. This will make
it so that when the InventoryButton_Pistol is clicked, Unity will pull the
pistol out if it's not the active tool, but put it away if it's already deployed:
if (name == "InventoryButton_Pistol"){
toolFunctionality.empActive = false;
if (toolFunctionality.flashlightActive){
StoreFlashlight();
}
 
Search WWH ::




Custom Search