I’m a newbie at Unity and Javascript. My player has a flashlight and I can holster it (play an animation and then set it inactive), but when I try to get it back active, it won’t work.
Here is my code:
#pragma strict
var Flashlight : GameObject;
function Update () {
if (animation.isPlaying == false)
{
animation.CrossFade("Idle");
}
if (Input.GetKey (KeyCode.LeftShift) && Input.GetKey (KeyCode.W))
{
animation.CrossFade("Run");
}
if (Input.GetKeyDown(KeyCode.F))
{
if (Flashlight.active == false)
{
Activate ();
}
else
{
Desactivate ();
}
}
}
function Activate ()
{
Flashlight.SetActiveRecursively(true);
}
function Desactivate ()
{
animation.CrossFade("Holster");
yield WaitForSeconds(0.8);
Flashlight.SetActiveRecursively(false);
}
Note that I’m also receiving an error: “The referenced script on this Behaviour is missing!”
I tried fixing it but with no luck.