Hey guys, I’m having a big problem with my script. It does all what I want it to do until I put a yield on it so that it waits for the animation to finish before it loads the new scene; instead it plays no animation and just goes straight to a new scene.
Script:
function Update ()
{
var hit :RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit, 5))
{
if(hit.collider.gameObject.tag == "Elevator")
{
if(Input.GetKeyDown(KeyCode.I))
{
hit.collider.gameObject.animation.Play("Elevator");
StartCoroutine();
Startagain();
}
}
}
}
function StartCoroutine (){
animation.Play(animation.clip.name);
yield WaitForSeconds (animation.clip.length + 2);
}
function Startagain (){
Application.LoadLevel(1);
}