Hello Guest

Author Topic: Animation doesn't start  (Read 3191 times)

xraezor

  • Newbie
  • *
  • Posts: 1
    • View Profile
Animation doesn't start
« on: February 27, 2013, 04:38:19 pm »
Hello, I'm a newbie in the forums (and using the 2D toolkit). First I want to apologize for my bad english, and second;
I've done that pressing the Axis horizontal the player change the animation to walkRight or walkLeft whichever is applicable, but the problem come when I want that pressing the key Space (or button Jump) the character should do the animation of Jump and according to where he was walking the animation should change to jumpLeft, jumpRight or jumpFront if he don't have pressing any button. I'm using this code:
Code: [Select]
using UnityEngine;
using System.Collections;

public class AnimController : MonoBehaviour {
    tk2dAnimatedSprite anim;
private GameObject SelectPlayer;
//Walk
bool walkingLeft = false;
bool walkingRight = false;
bool stopWalk = false;
//Jump
    bool jumpingLeft = false;
bool jumpingRight = false;

    void Start () {
if (SelectPlayer == null){
SelectPlayer = GameObject.FindGameObjectWithTag("Player");
}
        anim = GetComponent<tk2dAnimatedSprite>();
    }

    void Update () {
CharacterController controller = SelectPlayer.GetComponent<CharacterController>();
//animations
if (stopWalk == false){
if (Input.GetAxis ("Horizontal") > 0) { // walk right
walkingLeft = false;
walkingRight = true;
if(walkingRight == true){
if (anim.isPlaying () && anim.CurrentClip.name != "walkRight" || !anim.isPlaying ())
anim.Play ("walkRight");
}
} else if (Input.GetAxis ("Horizontal") < 0) { // walk left
walkingRight = false;
walkingLeft = true;
if(walkingLeft == true){
if (anim.isPlaying () && anim.CurrentClip.name != "walkLeft" || !anim.isPlaying ())
anim.Play ("walkLeft");
}
}
}else if (Input.GetButtonDown ("Jump")){ //jumps
if (walkingLeft == true){
walkingRight = false;
jumpingRight = false;
jumpingLeft = true;
if(jumpingLeft = true){ //jumpLeft
anim.Play ("jumpLeft");
}
}else if (walkingRight == true){
walkingLeft = false;
jumpingLeft = false;
jumpingRight = true;
if(jumpingRight = true){ //jumpRight
anim.Play ("jumpRight");
}
}else{ //jumpFront
walkingLeft = false;
jumpingLeft = false;
jumpingRight = false;
walkingRight = false;
anim.Play ("jumpFrontal");
}
} else { // idle
if (walkingRight == true){ //idle right
if (anim.isPlaying () && anim.CurrentClip.name != "idleRight" && anim.CurrentClip.name != "unhide" || !anim.isPlaying ()) {
anim.Play ("idleRight");
}
}
if (walkingLeft == true){ //idle left
if (anim.isPlaying () && anim.CurrentClip.name != "idleLeft" && anim.CurrentClip.name != "unhide" || !anim.isPlaying ()) {
anim.Play ("idleLeft");
    }
    }
        }
    }

public void Colgando(){
stopWalk = true;
}

public void ColgandOff(){
stopWalk = false;
}
}
(There are parts in spanish because I'm spanish)
The problem is that when you push the jump button the character doesn't change the animation :S.
How can I solve this?
Thanks :)
« Last Edit: February 27, 2013, 04:42:27 pm by xraezor »