- Home /
How to resume animation where it left off?
I am making a first person shooter game in unity. I have a bar on the top of the screen that is equal to the number of bullets in the gun. Problem is, When I shoot a bullet, I want the bar to decrease = to the number of bullets shot. I have a decreasing animation that works perfectly. I need to do something like this.
When I shoot the gun, play animation. If Im not shooting, stop animation. If im shooting play animation where it left off.
// Checks every frame
void Update () {
// Display how much ammo is remaining
text.text = "" + Ammo;
// If the user has pressed spacebar and there are bullets inside the gun,
if(Input.GetKey("space") && Ammo >= 1)
{
// Subtract the ammo
Ammo = Ammo - 1;
// Play reload stop
anim.Play("ReloadStop");
}
// If user is not shooting the gun,
else
{
// Stop the animation
anim.Stop("ReloadStop");
}
Also, why is my Update function not inside the ?
Answer by hamza37 · Apr 04, 2020 at 07:01 PM
i know its late in case if someone is still looking here is the way you can do it......
public Animator Anim;
void Start()
{
Anim.speed = 1;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Anim.speed = 0;//pause the animation
}
if (Input.GetKeyDown(KeyCode.A))
{
Anim.speed = 1;//resume the animation
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Floating boss Hands, can't move bones of hands for attacks 0 Answers
Efficient way to instantiate a sprite that plays an animation then destroys itself? (3d space) 1 Answer
UI Text Alpha not fading out in animation 0 Answers
Issue with mecanim playing an animation using setbool 1 Answer