My animation is working but unity keep saying that my Animator has not been initialized error Here my Code:
using UnityEngine;
using System.Collections;
public class Player: MonoBehaviour {
public float maxspeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
void Start ()
{
anim = GetComponent<Animator> ();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxspeed, GetComponent<Rigidbody2D>().velocity.y);
if (move > 0 && !facingRight){
Flip ();
} else if (move < 0 && facingRight) {
Flip ();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}