Animation Scripting C# Error

I have already asked this question, but I really need a through walk through on how to fix it, I would really appreciate this because I am doing self teaching but I cannot figure this error out…

The Error is :

NullReferenceException: Object reference not set to an instance of an object
EnemyAnimation.Start () (at Assets/The Game/Scripts/EnemyAnimation.cs:24)

using UnityEngine;
using System.Collections;

public class EnemyAnimation : MonoBehaviour
		public Animation _animation;
		// Use this for initialization
		void Start ()
				_animation = GetComponentInChildren<Animation> ();
				string animationToPlay = "";
				switch (Random.Range (0, 3)) {
				case 0:
						animationToPlay = "Move1";
				case 1:
						animationToPlay = "Move2";
				case 2:
						animationToPlay = "Move3";
		_animation [animationToPlay].wrapMode = WrapMode.Loop;
		_animation.Play (animationToPlay);
		_animation[animationToPlay].normalizedTime = Random.value;
		// Update is called once per frame
		void Update ()


Here are some pictures on how I added it to the component on unity.
Hopefully it is visible.

Also where it says Animation in the script component, it wont let me add anything, when I go to add something it gives me the options and when I select an animation, it does not update…

If the line numbers in your posted code match the error, that would suggest that either:

  1. “_animation” is null (meaning that the GetComponentInChildren() call above returned null), or
  2. “_animation[animationToPlay]” is null.

As far as why these are null, that depends on what you’re trying to do. Can you explain what you’re trying to do with this code? Why are you calling GetComponentInChildren() to find the animation, for instance?