Game Development Reference
In-Depth Information
We already know how to turn objects on and off (GameObject.active = true/
false;), we just need to declare the variables and then have them turned on
and off in the right places.
Step 32: Declare three new private variables at the top of the script:
private var aegisFlashlight : GameObject;
private var aegisFlashlightLight : GameObject;
private var aegisPistol : GameObject;
Why?
We're declaring a variable to house the geometry of the flashlight
(aegisFlashlight), the light (created way back when working in the
hallway), and the pistol geometry (aegisPistol). We'll populate these here
in our Awake function in a bit.
Step 33: Populate these new private variables in the Awake function. So it
should read like this:
function Awake(){
mainCamera = GameObject.Find("Main Camera");
toolFunctionality = mainCamera.GetComponent("AC_Tool
FunctionalityScript");
aegisArms = GameObject.Find("AegisChung_Arms_Prefab");
aegisFlashlight = GameObject.Find("AC_Flashlight");
aegisFlashlightLight = GameObject.Find("Flashlight");
aegisPistol = GameObject.Find("AC_Pistol");
}
Why?
Again, the assumption at this point is that we won't be renaming things,
and that we go out and find only one of the objects. Again, the benefit
of this is that we needn't populate them within Unity's editor—the
drawback is that if we rename something, this script will break.
Step 34: Activate these and deactivate them in the appropriate places
within the ReadyPistol, StorePistol, ReadyFlashlight, and StoreFlashlight
functions:
function ReadyPistol(){
aegisPistol.active = true;
aegisArms.animation["PistolReady"].speed = 1;
aegisArms.animation.Play("PistolReady");
yield WaitForSeconds (aegisArms.animation.clip.length);
toolFunctionality.pistolActive = true;
}
function StorePistol(){
aegisArms.animation["PistolReady"].speed = -1;
Search WWH ::




Custom Search