(2d game)
I’m trying to manipulate the sprite animation script on a CharacterController via a Vector3 that I’m using for its velocity. The velocity.x varies from -4 to 4 (which I’ve verified via print(velocity.x) in the console).
To handle animations, I’ve set up some simple if/else statements, but if we are moving (velocity.x > 0 || velocity.x < 0), it won’t get to the else of the statement.
I’m relatively new to C# and Unity, so any help would be super-appreciated. Here’s the code:
//Handle Idle Animations
if (velocity.x == 0)
{
if (moveDirection == 1)
{
aniPlay.CreateSprites(16, 16, 0, 0, 16, 12); //Works
}
else
{
aniPlay.CreateSprites(16, 16, 0, 1, 16, 12); //Works
}
}
else
//Handle Moving Animations
if (velocity.x > 0)
{
if (velocity.x <= 2)
{
aniPlay.CreateSprites(16, 16, 0, 2, 10, 12); //Always plays this when moving right
}
else if(velocity.x > 2)
{
print("I got here"); //Never prints
aniPlay.CreateSprites(16, 16, 0, 6, 16, 12); //Never plays this
}
}
else
if(velocity.x < 0)
{
if (velocity.x >= -2)
{
aniPlay.CreateSprites(16, 16, 0, 3, 10, 12); //Always plays this when moving left
}
else
{
aniPlay.CreateSprites(16, 16, 0, 7, 16, 12); //Never plays this
}
}