Hello
I’ve been working on a small 2D platformer game for my little brother. The main character (a monkey) is supposed to be able to use a sword to damage enemies. I’ve come across a problem trying to animate this sword. The animation is supposed to be pretty simple:
- First frame: sword is disabled
- Second frame: sword becomes enabled
- Middle frame: sword’s X value has changed so it looks like it’s thrusting forward
- Second to last frame: sword enabled
- Last frame: sword disabled
Below, I will include a few pictures of the animation, animator and the code I used to call the animation.
The problem is that sometimes the animation does display correctly, but most of the time it doesn’t do anything.
I’m still fairly new to using animations in Unity, and I was wondering if anyone could help me solve this little problem. Many thanks in advance.
Animator
Transition any state - sword attack
Transition sword attack - idle
Animation
Code used
if (anim.GetBool("Sword"))
{
anim.SetBool("Sword", false);
}
if (Input.GetKeyUp (KeyCode.Mouse0))
{
anim.SetBool("Sword", true);
}
[EDIT]
Extra information:
- I put a Debug.Log in the statement where it sets the Sword bool to true, which does show up when I press the button, but I don’t see the “Sword” checkbox in the animator being ticked on when I do so
- The code for this animation is in the same script as the one in which I control the player’s jumping and walking animations, although these two use different values (a bool called “On Ground” and a float called “Speed”) to control the animations