- Home /
Help Animating a Texture
Im using a script off of the wiki to animate my texture:
This basically is what turns a 2D SpriteSheet into an animated character.
Here's the code I'm using to assign keys to each row of the SprieSheet:
I have a 4x4 Sprite Sheet, the rows start at 0 instead of 1. (row = 0 would be the first row)
Anyway, As you can see I assigned multiple keys to two specific rows, you can read the comments in the code for more detail. But for some reason its only showing row 0 and row 1 And the Unity console isnt even giving me errors.
Sprite Sheet:
Row 0 is my character just stationary
Row 1 is of my character running
Row 2 is of my Character shooting, while stationary
Row 3 is of my character Shooting, while running
The game plays as if Rows 2 and 3 just dont exist, nor do the lines in the code.
Sorry if I dont explain very well, Im very, very new to Java and Unity.
Anyone have an idea whats going wrong?
Answer by Adamcbrz · Aug 21, 2013 at 04:05 AM
Your if statement in you second image won't ever set the state to 2 or 3 because as soon as you do you change it to 0 or 1.
You need to change your code to be logically like the following. ( this is not functional code but should help you restructure your code)
If( keydown(w) && keydown(a) )
ShowFrame = 2
else if ( keydown(w) && keydown(d) )
ShowFrame = 3
else if ( keydown(w) )
ShowFrame = 3
else if ( keydown(a) || keydown(d) )
ShowFrame = 1
else
ShowFrame = 0
Ah. I guess it was all dependent on the order of the lines. Thanks!
Order was important but using the else if was another part of the problem.
Also if this answer solved your problem please make it as correct.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112639im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how character's legs(tps) move? 0 Answers
How would you make a shapeshifting mechanic in a game? 1 Answer
Playing sprint animation with vertical axis? 0 Answers
Enemy AI Animation 0 Answers
Why won't it run 1 Answer