Hello,
This may be the simplest question but I can’t seem to trigger an animation using JS in Unity 5.0. All of the examples online are for deprecated code, and so don’t seem to work with this version of Unity. Here is the code…
function Update (){
if(open){
//Open door
//play animation
}
else
{
//Close door
//do nothing
}
if(Input.GetKeyDown("4") && enter)
{
open = !open;
}
}
Now the animation is called openDoorNormal and is attached to the Animation component for the object, which is a door. I’ve tried the following…
door.GetComponent.<Animation>.Play("doorOpenNormal");
But it errors out. Actually now that I think about it, here is the full code…
private var open : boolean;
private var enter : boolean;
private var door : Transform;
//Main function
function Update (){
if(open){
//Open door
door.GetComponent.<Animation>.Play("doorOpenNormal");
}
else
{
//Close door
//do nothing
}
if(Input.GetKeyDown("4") && enter)
{
open = !open;
}
}
//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider)
{
if (other.gameObject.tag == "Activate")
{
enter = true;
}
}
//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider)
{
if (other.gameObject.tag == "Activate")
{
enter = false;
}
}
Thank you in advance for any suggestions…