Animation clip only plays once when button is pressed, and then will not play again
The question is pretty much summed up above. I have an animation that plays when a button is pressed, but then it no longer plays if I try to press it again. I feel like this will be a really easy thing to answer that I'm just overlooking, but I've been struggling for a while. Also in the screenshot of the script below please ignore the animation bool variable- I'm taking that out. Thanks in advance!
Answer by Code1345 · Aug 07, 2017 at 10:42 PM
I have an answer!
Looking at my script, to rewind the animation, you just use the line of code I did right under "GunFireAnimator.Play("gunshot); and add the name of your animation in the parenthesis, as well as the component name right before the .Play . I hope this helps someone out!
Well that's obvious.......
Thanks for this solution, solved my issue which was the same as yours.
I literally logged in just to thank you for this! I had messing around with it for SO LONG before just googling and now it works for me!
Answer by JudeJeremy · Mar 05, 2021 at 11:30 PM
I tried replicated this code but for some reason its still not working for me when i press my key, which in this case is r, Once I press r the animation runs but when i try press r again it doesnt work. Here is my code`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AnimationRunner : MonoBehaviour { public GameObject ItalianGun; private Animator Reload;
void Start ()
{
Reload = GetComponent<Animator>();
}
void Update()
{
if (Input.GetButtonDown("RKey"))
{
Reload.Play("ReloadAnimation");
ItalianGun.GetComponent<Animator>().Play("ReloadAnimation");
}
}
}`