- Home /
Animation Scripting Help #C
I keep getting this error: NullReferenceException: Object reference not set to an instance of an object EnemyAnimation.Start () (at Assets/The Game/Scripts/EnemyAnimation.cs:24)
I am really new to this and I would really appreciate some help!
using UnityEngine;
using System.Collections;
public class EnemyAnimation : MonoBehaviour
{
Animation _animation;
// Use this for initialization
void Start ()
{
_animation = GetComponentInChildren<Animation> ();
string animationToPlay = "";
switch (Random.Range (0, 3)) {
default:
case 0:
animationToPlay = "Move1";
break;
case 1:
animationToPlay = "Move2";
break;
case 2:
animationToPlay = "Move3";
break;
}
_animation [animationToPlay].wrapMode = WrapMode.Loop;
_animation.Play (animationToPlay);
_animation[animationToPlay].normalizedTime = Random.value;
}
// Update is called once per frame
void Update ()
{
}
}
Comment
Answer by Saravia95 · Apr 16, 2014 at 05:15 PM
Ive added the script to the enemy, but it is still not working
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
c# how to get to idle from walk 0 Answers
Question about attaching game objects to certain bones 1 Answer
What is way to flash the screen WITHOUT using a Texture? 2 Answers
c# how to refresh my targeting list 2 Answers