Hi im having some trouble playing my walk animation when the player is grounded.
When the player is not grounded, the jump animation should play, which works fine.
But when the player hits the ground, he just stops and stays in jump animation. The player should automatically start walking!
Please help!
I have a groundCheck game object set underneath the player
And jump animation is just one sprite looped.
tk2dSpriteAnimator animator;
private Transform groundCheck; // A position marking where to check if the player is grounded.
private bool grounded = false; //Whether or not the player is grounded.
// Use this for initialization
void Start ()
{
animator = GetComponent<tk2dSpriteAnimator> ();
groundCheck = transform.Find("groundCheck");
Invoke ("PlayInABit", 5f);
}
// Update is called once per frame
void Update ()
{
grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Layer 0"));
if(animator.IsPlaying("Walk") && animator.CurrentFrame >= 1)
{
transform.Translate (1.5f * Time.deltaTime, 0, 0);
}
if(grounded)
{
Debug.Log (grounded.ToString());
animator.Play ("Walk");
}
else
{
Debug.Log (grounded.ToString());
animator.Play ("Jump");
}
}
void PlayInABit()
{
animator.Play ("Walk");
}