- Home /
Animation not playing until i move character.
Hey!
So the thing is, my character animations work as intended when walking, jumping, falling, standing idly etc. BUT it doesn't work until I've given an input to the horizontal axis (aka moved left or right), and jumping doesn't do anything either.
So, no idle/jumping animations are playing if I haven't walked some before.
EDIT: Automatic play and default animation in ex2D settings don't help.
using UnityEngine;
using System.Collections;
public class Controls : MonoBehaviour {
public exSpriteAnimation spAnim;
private string last_anim;
private double last_height;
private double new_height;
float axis;
string play;
string direction;
private bool falling;
private bool jumping;
private bool grounded;
private bool idle;
private bool strafing;
void Update() {
last_height = new_height;
new_height = transform.position.y;
axis = Input.GetAxisRaw ("Horizontal");
// Conditions
if (axis < (-0.015)){
direction = "left";
//Debug.Log ("left");
strafing = true;
idle = false;
}else if (axis > 0.015)
{
direction = "right";
//Debug.Log ("right");
strafing = true;
idle = false;
}else
{
//Debug.Log ("0");
strafing = false;
idle = true;
}
if ((int)last_height < (int)new_height)
{
falling = false;
jumping = true;
grounded = false;
}
if((int)last_height > (int)new_height)
{
falling = true;
jumping = false;
grounded = false;
}
if(last_height == new_height)
{
grounded = true;
jumping = false;
falling = false;
}
// idling left
if(direction=="left" && !falling && !jumping && grounded && idle && !strafing)
{
play = "l_idle";
//Debug.Log ("l_idle");
}
// idling right
if(direction=="right" && !falling && !jumping && grounded && idle && !strafing)
{
play = "r_idle";
//Debug.Log ("r_idle");
}
// running left
if(direction=="left" && !falling && !jumping && grounded && !idle && strafing)
{
play = "l_walk";
//Debug.Log ("l_walk");
}
// running right
if(direction=="right" && !falling && !jumping && grounded && !idle && strafing)
{
play = "r_walk";
//Debug.Log ("r_walk");
}
// jumping left
if(direction=="left" && !falling && jumping && !grounded)
{
play = "l_jump";
//Debug.Log ("l_jump");
}
// jumping right
if(direction=="right" && !falling && jumping && !grounded)
{
play = "r_jump";
//Debug.Log ("r_jump");
}
// falling left
if(direction=="left" && falling && !jumping && !grounded)
{
play = "l_fall";
//Debug.Log ("l_fall");
}
// falling right
if(direction=="right" && falling && !jumping && !grounded)
{
play = "r_fall";
//Debug.Log ("r_fall");
}
// Play
if(!spAnim.IsPlaying(play + "_ani"))
{
spAnim.Play(play + "_ani");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Combine Array of Sprites to Form One Sprite 0 Answers
SpriteManager 2 1 Answer
C# Make Child Not Animate Looped Animation 1 Answer
Using iTween for custom variables 3 Answers
Create light shapes on plane using C# (similar to the game Closure) 2 Answers