This question was 
             closed Mar 03, 2017 at 02:43 PM by 
             PresidentPorpoise for the following reason: 
             
 
            The question is answered, right answer was accepted
 
               Question by 
               PresidentPorpoise · Nov 28, 2016 at 04:26 AM · 
                c#animationscripting problemscript erroranimation clip  
              
 
              Errors in script when trying to play animation clips
Hello, I am trying to write a script that lets me use a public variables to hold animation clips. I am getting the following errors when I try to call the variables and play the animation.
 
 
Here is the actual script (had some help on the script earlier to make it interchangeable in the first place, so that is why there are comments):
 public class ContainerOpen : MonoBehaviour
 {
     public AnimationClip slideOutAnimation; // drag and drop this in the inspector
     public AnimationClip slideInAnimation;  // drag and drop this in the inspector
 
     private bool open;
     private float distance;
 
     private GameObject player;
     private Animation animation;
 
     void Awake()
     {
         distance = 3;
         open = false;
     }
 
     void Start()
     {
         // do the find once here
         player = GameObject.Find ("FPSController");
         if (player == null)
         {
             Debug.LogError ("Unable to find game object FPSController. Please fix and try again.");
                 }
 
                 // get a reference to the attached Animation component
                 animation = gameObject.GetComponent<Animation>();
                 if (animation == null)
                 {
                     Debug.Log("There is no Animation component attached to the current object. Adding one...");
                     animation = gameObject.AddComponent<Animation>();
                 }
 
                 // make sure the animation clips have been set
                 if (slideOutAnimation == null)
                 {
             Debug.LogError ("slideOutAnimation was not set in the inspector. Please set and try again.");
                         }
                         if (slideInAnimation == null)
                         {
             Debug.LogError ("slideInAnimation was not set in the inspector. Please set and try again.");
                                 }
                                 }
 
                                 void OnMouseOver()
                                 {
                                     if ((player != null) && (slideOutAnimation != null) && (open == false))
                                     {
                                         if (Input.GetMouseButton (0)) 
                                         {
                                             Vector3 playerPosition = player.transform.position;
                                             if (Vector3.Distance (playerPosition, transform.position) <= distance) 
                                             {
                                                 animation.Play (slideOutAnimation);
                                                 open = true;
                                             }
 
                                         }
                                     }
 
                                     if ((player != null) && (slideInAnimation != null) && (open == false))
                                     {
                                         if (Input.GetMouseButton (1)) 
                                         {
                                             Vector3 playerPosition = player.transform.position;
                                             if (Vector3.Distance (playerPosition, transform.position) <= distance) 
                                             {
                                                 animation.Play (slideInAnimation);
                                                 open = false;
                                             }
                                         }
                                     }
 
                                 }
 }
 
                 
                0ecca5a9f0dfe995c45000a7c7b91f7e.png 
                (12.4 kB) 
               
 
                
                 
                89d8e139b9d36e41d490a78c1e27e1ba.png 
                (22.6 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Adam-Mechtley · Nov 28, 2016 at 09:50 AM
Hi! As the warning message indicates, MonoBehaviour.animation already exists as a property, albeit one that is going to be removed later. Simply give your field a new name or use the new keyword as indicated. E.g., either of these:
 private Animation m_Animation; // different name
 new private Animation animation; // using "new" keyword
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                