Question by
beyluta · Feb 20, 2016 at 10:04 AM ·
animationanimatoranimator controlleranimationsanimationclip
Can't play an animation from the Animator
i always get this error when i try to play the animation:
NullReferenceException: Object reference not set to an instance of an object
using UnityEngine;
using System.Collections;
public class Akscript : MonoBehaviour {
Animator anim;
// Use this for initialization
void Start () {
anim.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown("1"))
{
anim.SetBool("IsRunning", true);
}
}
}
Comment
Best Answer
Answer by beyluta · Feb 20, 2016 at 11:06 AM
Never mind, just put a "Public" in front of Animator anim; and it'll appear in the inspector, then just select your game object