Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Door doesn't open but closes...

Discussion in 'Scripting' started by Luke3671, Mar 9, 2015.

  1. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    52
    This is in Unity 5
    Hello,
    I'm not the best at coding (Prob why its not working :p )... 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:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Door : MonoBehaviour
    5. {
    6.     public AudioClip open, close;
    7.    
    8.     void onTriggerEnter(Collider Player)
    9.     {
    10.         if (Player.transform.tag == "Player")
    11.         {
    12.             GetComponent<Animation>().Play("Open");
    13.             AudioSource.PlayClipAtPoint(open, new Vector3(0,0,0));
    14.         }
    15.     }
    16.    
    17.     void OnTriggerExit(Collider Player)
    18.     {
    19.         if (Player.transform.tag == "Player")
    20.         {
    21.             StartCoroutine ("ExitTimer");
    22.         }
    23.     }
    24.    
    25.     IEnumerator ExitTimer()
    26.     {
    27.         yield return new WaitForSeconds(2);
    28.         GetComponent<Animation>().Play ("Close");
    29.         AudioSource.PlayClipAtPoint(close, new Vector3(0,0,0));
    30.        
    31.     }
    32. }
    If you can help be great
    Thank you
     
  2. Joe64

    Joe64

    Joined:
    Jun 13, 2012
    Posts:
    9
    onTriggerEnter should be OnTriggerEnter (capital O).
    Hint: When it's not highlighted in red then there must be a typo.
     
    Luke3671 likes this.
  3. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    52
    Thank you very much!