door Script

i made a script for my doors to animate when the player enters the collider, and after 5 seconds the animation play in reverse, however once its done playing in reverse it wont re-open here is my script.

var sound : AudioClip;
var Door : GameObject;

function OnTriggerEnter (other : Collider)
{

var contact : String = other.transform.name;

if (contact == “FirstPersonController”)
{
Door.animation.Play(“Take 0”);
// Play sound
if (sound)
AudioSource.PlayClipAtPoint(sound, transform.position);

yield WaitForSeconds(5.0); // wait for 5 seconds
// play animation in reverse
animation[“Take 0”].speed = -1.0;
}
}

1 Like

i think the problem is that the animation isnt stopping playing backwards, i put animation.stop underneath that last line but then it wont shut.

yield WaitForSeconds(5.0); // wait for 5 seconds
// play animation in reverse
animation[“Take 0”].speed = -1.0;
// Stop the walk animation
animation.Stop(“Take 0”);
}
}

and ive also tried

yield WaitForSeconds(5.0); // wait for 5 seconds
// play animation in reverse
animation[“Take 0”].speed = -1.0;
// Rewind the Door animation to the start
animation.Rewind(“Take0”);
}
}

u must to set up again ur speed to 1 , because it’ll still -1 if u don’t .
try this :

// before open ur door, just set datas to there initials value
animation[“open_the_door”].time = 0;;
animation[“open_the_door”].speed = 1;
animation.Play(“open_the_door”) ;

// close the door just by the way that u did