Hey guys, I’m currently trying to figure out how to Animate in Unity 2D and with that I stumbled into transitioning. Although I have no idea how to call the transition parameters into code, this is my current attempt which is giving the error above. I dont know why Its giving me the error as in Start() I called the animator component into the script.
(full error: NullReferenceException: Object reference not set to an instance of an object
MovementFixed.Update () (at Assets/Script/MovementFixed.cs:21)
)
Any help would be great!
Thanks!
Animator animator;
public float speed = 1.5f;
public int Direction = 0;
void start(){
animator = this.GetComponent<Animator>();
}
void Update ()
{
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.position += Vector3.left * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
if (Input.GetKey (KeyCode.RightArrow)) {
transform.position += Vector3.right * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
if (Input.GetKey (KeyCode.UpArrow)) {
transform.position += Vector3.up * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.position += Vector3.down * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
}
}