Inspector won't let me add animation component?

//I’ve seen answers, however they don’t seem to fit my situation, either that or I’m just not understanding it <-----that’s probably it. It tells me I need to add an animation component to inspector named “Wavedash” But, I try to drag and drop it completely denies it. It’s confusing because it told me to drop an animation in inspector but its not allowing me to, that’s like telling me to play basket ball, but without a ball. What am I going to play with, a cube?
Scroll to Bottom to see what I’m saying
P.S. Sorry the codes a mess its 1:45 AM.

It’s a Mario platformer clone, with advanced techniques

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
 public float moveSpeed;
  public float jumpHeight;
   public float sprintSpeed;
	public string Identifier;
	 public GameObject player;
	  public bool DrawDefturtle;
	   public bool DrawDefturtle_;
	    public bool DrawFireBro;
	     public bool hasMushroom;
	      public bool invincible;
private Animator anim;
 public AudioClip Bounce;
  public AudioClip powerUp;
   public float waveDashenergy;
	Vector2 waveDash;
     public float wavedashSpeed;
      public float directionlooked;
       public bool iceOn;
        public bool dashnow;
	// Use this for initialization
	void OnCollisionEnter2D(Collision2D coll){
		//Allows me to "control" these objects
		GameObject.FindGameObjectWithTag ("Turtle");
		GameObject.FindGameObjectWithTag ("checkPoint");

if (coll.collider.tag == ("Turtle") && coll.collider.GetType () == typeof(EdgeCollider2D)) {
			rigidbody2D.velocity = new Vector2 (0, 8);
			print ("Wow");
			Destroy (coll.collider.gameObject);
			DrawDefturtle = true;
			DrawFireBro = false;
			DrawDefturtle_ = false;
		}	
	
 if (coll.collider.GetType () == typeof(PolygonCollider2D) && coll.gameObject.name == "fireball" && hasMushroom == false && invincible == false) {
			transform.position = new Vector3 (-8, -11, -3);
			Debug.Log ("garbage");
			DrawFireBro = true;
			DrawDefturtle = false;
			DrawDefturtle_ = false;
			invincible = true;
			StartCoroutine(wait());
		}
  if (coll.collider.GetType () == typeof(PolygonCollider2D) && coll.gameObject.name == "RedTurtle" && hasMushroom == false) {
			transform.position = new Vector3 (-8, -11, -3);
			Debug.Log ("garbage");
			DrawDefturtle_ = true;
			DrawFireBro = false;
			DrawDefturtle = false;
			invincible = true;
			StartCoroutine("wait");
		}
   if (coll.collider.gameObject.tag == "YOSHI") {
			audio.PlayOneShot (Bounce);
			rigidbody2D.velocity = new Vector2 (-8, 8);

		}
	if (coll.collider.tag == "mushroom") {
			hasMushroom = true;
			Debug.Log ("I can take a hit!");
			Destroy (coll.collider.gameObject);
	 if (hasMushroom == true){
				anim.enabled = true;
				audio.PlayOneShot (powerUp);
				//This tells the computer to make the player a little bet smaller!
				transform.localScale -= new Vector3(0.2F, 0.2F, 0);
				CircleCollider2D mychangeofHeight = transform.GetComponent<CircleCollider2D> ();
				//Changed the radius to a higher number because the animation made the sprite bigger!
				mychangeofHeight.radius = 0.70f;

				//GBA, SMW!
				Debug.Log ("Just, what I needed!");



		}
		}
		//The if statement is telling the computer what conditions need to be made in order for this "if" statement to work!
if (coll.collider.GetType () == typeof(PolygonCollider2D) && coll.gameObject.name == "RedTurtle" && hasMushroom == true) {
			Debug.Log ("Mushroom lost!");
			hasMushroom = false;
			invincible = true;
			StartCoroutine(wait());
		}
 if (coll.collider.GetType () == typeof(PolygonCollider2D) && coll.gameObject.name == "fireball" && hasMushroom == true) {
			Debug.Log ("Mushroom lost!");
			hasMushroom = false;
			invincible = true;
		}
 if (coll.collider.GetType () == typeof(PolygonCollider2D) && coll.gameObject.name == "fireball" && hasMushroom == false && invincible == true){
			Debug.Log ("Ha Loser I have invincibility frames!");
		
		}
	}
	void Start () {
		//What bool's should start out as
DrawDefturtle = false;
 DrawDefturtle_ = false;
  DrawFireBro = false;
   hasMushroom = false;
	invincible = false;
	 anim = GetComponent<Animator>();
	  anim.enabled = false;
	   player.GetComponent<PolygonCollider2D>().enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
		//Remember GetKeyDown activates only the same frame you press it!
if (Input.GetKeyDown (KeyCode.UpArrow)) {
			rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, jumpHeight);
		}
 if (Input.GetKey (KeyCode.RightArrow)) {
			rigidbody2D.velocity = new Vector2 (moveSpeed, rigidbody2D.velocity.y);
		}
  if (Input.GetKey (KeyCode.LeftArrow)) {
			rigidbody2D.velocity = new Vector2 (-moveSpeed, rigidbody2D.velocity.y);
		}
	if (Input.GetKey (KeyCode.LeftArrow) && Input.GetKey (KeyCode.Z)) {
			rigidbody2D.velocity = new Vector2 (-sprintSpeed, rigidbody2D.velocity.y);
		}
	 if (Input.GetKey (KeyCode.RightArrow) && Input.GetKey (KeyCode.Z)) {
			rigidbody2D.velocity = new Vector2 (sprintSpeed, rigidbody2D.velocity.y);
		}
	  if (Input.GetKeyDown (KeyCode.C) && Input.GetKey (KeyCode.RightArrow)) {
			directionlooked = 1;
	   if (hasMushroom == true && waveDashenergy >= 10) {
				waveDashenergy = waveDashenergy - 10f;
				transform.Translate(waveDash);
				StartCoroutine("ice");
				iceOn = true;
				waveDash.x = directionlooked * wavedashSpeed* Time.deltaTime;
				transform.Translate (waveDash);

			}
		}

	}
	void OnGUI(){
		//Tells what GUI should be up at a certain point in time!
if(DrawDefturtle == true){
		GUI.Box(new Rect(0, 0, 200, 90), "Red Turtle: An Easy Enemy 

to defeat walks back and forth,
Simple!");
DrawDefturtle_ = false;
DrawFireBro = false;
}
if(DrawDefturtle_ == true){
GUI.Box(new Rect(0, 0, 200, 90), “Dude How did you die
easiest enemy to kill, loser!”);
DrawDefturtle = false;
DrawFireBro = false;
}
if(DrawFireBro == true){
GUI.Box(new Rect(0, 0, 300, 180), “FireBro DD V2.0: These Enemies
are Dash Dancing Monsters and
cannot be jumped
on, nor killed for that matter, only his fireballs can
kill you!”);
DrawDefturtle = false;
DrawDefturtle_ = false;
}
}
IEnumerator wait(){
if(invincible == true){
//Tells the computer to “calm down” and wait!
yield return new WaitForSeconds (2f);
invincible = false;

}
}
	IEnumerator ice(){
 if(iceOn == true){
			//Same!
  player.GetComponent().enabled = true;
   yield return new WaitForSeconds(1f);
	anim.enabled = true;
	 animation.Play("Wavedash");// <---tells me I need an animation component with that name however if I drag and drop it "declines" it
	  Debug.Log("Holymoly");
	   player.GetComponent<PolygonCollider2D>().enabled = false;
}
	}
}

1 Answer

1

An Animation component is nothing you can drag onto the inspector. What you probably tried dragging was the AnimationClip. You need to add it via AddComponent and then add the clip to the slot it then shows in the inspector.
But as I now see, at the Top you added an Animator variable named anim. That’s Mechanim and the preferred way of animating and a different component, which also works different. But you can stick to Animation as long as Unity does not strip it :slight_smile:
If you do, you need to configure your animation clip to be legacy by selecting it, switch to debug mode on the little cog symbol in the inspector and tick the option. then better switch back to normal mode again.