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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity 5 Error Script :(

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

  1. Luke3671

    Luke3671

    Joined:
    Jul 6, 2014
    Posts:
    52
    Hello,
    Sorry 2 trouble all, But myself and my mate are new to unity... We trying to make it so when player walks into door it triggers to open: We have made this script:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Door : MonoBehaviour
    6. {
    7.     public AudioClip open, close;
    8.  
    9.     void onTriggerEnter(Collider Player)
    10.     {
    11.         if (Player.transform.tag == "Player")
    12.         {
    13.             GetComponent<Animation>().play("Open");
    14.             AudioSource.PlayClipAtPoint(open, new Vector3(0,0,0));
    15.         }
    16.     }
    17.  
    18.     void OnTriggerExit(Collider Player)
    19.     {
    20.         if (Player.transform.tag == "Player")
    21.         {
    22.             StartCoroutine ("ExitTimer");
    23.         }
    24.     }
    25.  
    26.     IEnumerator ExitTimer()
    27.     {
    28.         yield return new WaitForSeconds(2);
    29.         GetComponent<Animation>().Play ("Close");
    30.         AudioSource.PlayClipAtPoint(close, new Vector3(0,0,0));
    31.      
    32.     }
    33. }
    34.  
    But i'm getting these errors:
    Door.cs(14,14): Error CS0117: 'UnityEngine.Animation' does not contain a definition for 'play' (CS0117) (Assembly-CSharp)
    &
    Door.cs(29,29): Error CS1061: 'UnityEngine.Animation' does not contain a definition for 'play' and no extension method 'play' accepting a first argument of type 'UnityEngine.Animation' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp)

    I'm using unity 5 btw. If anyone can help me fix this it will be great,
    Thank you very much
    Luke
     
  2. Ohrm

    Ohrm

    Joined:
    Dec 3, 2012
    Posts:
    4
    "GetComponent<Animation>().play("Open");" needs the play to have a capital P.