This is in Unity 5
Hello,
I’m not the best at coding (Prob why its not working
)… My mate helped me work on this, But i have done this video to show u want it’s doing for me;
When “Player” goes into Trigger… The door doesn’t open but when you come out of the trigger the Animation starts from Open to Closed. Is the code wrong or have i done something wrong? How i made the Animation for the doors were copy the door 2 times add open Animation to 1 and close to the other then remove them.
The code can be found here:
using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour
{
public AudioClip open, close;
void onTriggerEnter(Collider Player)
{
if (Player.transform.tag == "Player")
{
GetComponent<Animation>().Play("Open");
AudioSource.PlayClipAtPoint(open, new Vector3(0,0,0));
}
}
void OnTriggerExit(Collider Player)
{
if (Player.transform.tag == "Player")
{
StartCoroutine ("ExitTimer");
}
}
IEnumerator ExitTimer()
{
yield return new WaitForSeconds(2);
GetComponent<Animation>().Play ("Close");
AudioSource.PlayClipAtPoint(close, new Vector3(0,0,0));
}
}
If you can help be great
Thank you