1
Support / Re: Sprite Animation Issue
« on: February 01, 2013, 09:18:09 pm »
Thank you unikron! Once i updated to 1.90 it all worked perfectly.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
using UnityEngine;
using System.Collections;
public class AnimControllerTest : MonoBehaviour {
public float runSpeed;
public float gravity;
Vector2 velocity = Vector2.zero;
tk2dAnimatedSprite anim;
void Start ()
{
anim = GetComponent<tk2dAnimatedSprite>();
}
void Update ()
{
CharacterController player = GetComponent < CharacterController > ();
if (player.isGrounded)
{
velocity = new Vector2 (Input.GetAxis ("Horizontal"),0);
WalkAndRun();
}
velocity.y -= gravity * Time.deltaTime;
player.Move (velocity * Time.deltaTime);
}
void WalkAndRun ()
{
if (Input.GetKeyUp (KeyCode.RightArrow))
{
anim.Play("Idle Right");
anim.animationCompleteDelegate = null;
}
if (Input.GetKeyUp (KeyCode.LeftArrow))
{
anim.Play("Idle Left");
anim.animationCompleteDelegate = null;
}
if (Input.GetKeyDown (KeyCode.RightArrow))
{
velocity.x *= runSpeed;
anim.Play("Run Right");
anim.animationCompleteDelegate = null;
}
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
velocity.x *= runSpeed;
anim.Play("Run Left");
anim.animationCompleteDelegate = null;
}
}
}
using UnityEngine;
using System.Collections;
public class AnimControllerTest : MonoBehaviour {
public float runSpeed;
public float gravity;
public int lookDirection = 1;
Vector2 velocity = Vector2.zero;
tk2dAnimatedSprite anim;
void Start ()
{
anim = GetComponent<tk2dAnimatedSprite>();
}
void Update ()
{
CharacterController player = GetComponent < CharacterController > ();
if (player.isGrounded)
{
velocity = new Vector2 (Input.GetAxis ("Horizontal"),0);
WalkAndRun();
WhereAmILooking();
}
velocity.y -= gravity * Time.deltaTime;
player.Move (velocity * Time.deltaTime);
}
void WalkAndRun ()
{
if (velocity.x == 0 && lookDirection == 1)
{
anim.Play("Idle Right");
anim.animationCompleteDelegate = null;
}
if (velocity.x == 0 && lookDirection == 0)
{
anim.Play("Idle Left");
anim.animationCompleteDelegate = null;
}
if (velocity.x > 0 && lookDirection == 1)
{
velocity *= runSpeed;
anim.Play("Run Right");
anim.animationCompleteDelegate = null;
}
if (velocity.x < 0 && lookDirection == 0)
{
velocity *= runSpeed;
anim.Play("Run Left");
anim.animationCompleteDelegate = null;
}
}
void WhereAmILooking ()
{
if (velocity.x > 0)
{
lookDirection = 1;
}
if (velocity.x < 0)
{
lookDirection = 0;
}
}
}