OK, so I’m new to unity and me and a friend want to make a 2D game. So I’ve followed a tutorial on youtube and write this script:
Now, I’ve done some simple coding and programming before (but never in javascript) and i can understand the code.
With this script the animation changes between walking / jumping / idle (it is connected to this javascript http://wiki.unity3d.com/index.php/Animating_Tiled_texture_-_Extended), but when space (the jump button) is pushed and the sprite jumps, if you keep holding space the character will still be in the jump animation. How c
So here comes the question:
What can I do to make the character change back to the idle animation when hitting the ground (when the player is holding the jump button)?
And can I have another animation for when the character is on his way down?
Note: English is not my first language so I’m sorry that my formulation isn’t the best
#pragma strict
function Start () {
}
function Update () {
var AT = gameObject.GetComponent(AnimateTexture); //Store the AnimateTexture script
if(Input.GetKey("space")) { //Player jumps
AT.rowNumber = 2; //Start jumping animation
}
else if(Input.GetKey("a")) { //Player moves left
AT.rowNumber = 1; //Start running animation
}
else if(Input.GetKey("d")) { //Player moves right
AT.rowNumber = 1; //Start running animation
}
else if(Input.GetKey("left")) { //Player moves left
AT.rowNumber = 1; //Start running animation
}
else if(Input.GetKey("right")) { //Player moves right
AT.rowNumber = 1; //Start running animation
}
else { //Player doesn't press anything
AT.rowNumber = 0; //Return back to the idle animation
}
}