Animator object not working.
I have created two animator state one is walk and another one is idle,working processes are 1) When user not use keyboard at that time the character don't move that mean it is in idle state, 2)When users hit o the keyboard at that time the character move with animation Here is the code public float speed = 8f, maxVelocity=4f; private Rigidbody2D myBody; private Animator anim; void Awake(){ myBody = GetComponent (); } void Start () {
}
void FixedUpdate () {
PlayerMoveKeyboard ();
}
void PlayerMoveKeyboard(){
float forceX = 0f;
float vel = Mathf.Abs (myBody.velocity.x);
float h = Input.GetAxisRaw ("Horizontal");
if (h > 0) {
if (vel < maxVelocity)
forceX = speed;
//anim.SetBool("Walk", true);
} else if (h < 0) {
if (vel < maxVelocity)
forceX = -speed;
//anim.SetBool("Walk", true);
} else {
anim.SetBool ("Walk", false);
}
myBody.AddForce (new Vector2 (forceX, 0));
}
I received 'NullReferenceException: Object reference not set to an instance of an object Player.PlayerMoveKeyboard () (at Assets/Scripts/Player Scripts/Player.cs:48) Player.FixedUpdate () (at Assets/Scripts/Player Scripts/Player.cs:27)' this error message.
myBody = GetComponent () .. what does this do? Also where have you assigned to use animator component of the gameobject?
mybody = GetComponent<RigidBody>();
anim = GetComponent<Animator>();
i hope you have the above assigned.
Your answer
Follow this Question
Related Questions
How to play 'open door' animation on only one door? 0 Answers
Walk towards mouse cursor 0 Answers
Help with Enemy death Animation! 1 Answer
Animation Control by Float 2 Answers
Any Clue why this is turning 180? 2 Answers