Game Development Reference
In-Depth Information
Step 23: Create another function to store the pistol. Add this to the
bottom of the script:
function StorePistol(){
aegisArms.animation["PistolReady"].speed = -1;
aegisArms.animation["PistolReady"].time = aegisArms
.animation["PistolReady"].length;
aegisArms.animation.Play("PistolReady");
yield WaitForSeconds (aegisArms.animation.clip.length);
toolFunctionality.pistolActive = false;
}
Why?
This StorePistol function says, “set the speed of the animation PistolReady
to -1 (plays backward), then set its current time to the length of the
animation (think of this as fast-forwarding to the last frame), and then
play the animation.” This will play the animation backward, having
Aegis put the gun away. Finally, Unity waits until the animation of
putting the pistol away before it makes pistolActive false over in
AC_ToolFunctionalityScript.
Step 24: Create similar functions to ready the flashlight and put it away:
function ReadyFlashlight(){
aegisArms.animation["FlashlightReady"].speed = 1;
aegisArms.animation.Play("FlashlightReady");
yield WaitForSeconds (aegisArms.animation.clip.length);
toolFunctionality.flashlightActive =true;
}
function StoreFlashlight(){
aegisArms.animation["FlashlightReady"].speed = -1;
aegisArms.animation["FlashlightReady"].time = aegisArms
.animation["FlashlightReady"].length;
aegisArms.animation.Play("FlashlightReady");
yield WaitForSeconds (aegisArms.animation.clip.length);
toolFunctionality.flashlightActive = false;
}
Why?
Again, this is just the same thing, only talking to the animation
FlashlightReady. Remember that the names of these animations were
declared when the asset was first imported. We did this way back when
we brought in the full-body Aegis as well.
Note that since we are now turning the Booleans off and on in these
functions we'll need to remove them from the OnMouseDown function.
Search WWH ::




Custom Search