- Home /
Animation keeps repeating
Right now I have a basic melee script with animations, I have a stabbing animation (position animation) that works perfectly and a wacking (rotation animation) that just keeps repeating endlessly, They both use the same script:
private void Update() { MyThrowable = Hand.GetComponentInChildren(); MyWeapon = Hand.GetComponentInChildren(); if (MyWeapon != isActiveAndEnabled) { } else { attackTimer += Time.deltaTime; if (Input.GetMouseButtonUp(0) && attackTimer >= MyWeapon.attackCoolDown) { attackTimer = 0f; DoAttack(); Hand.GetComponentInChildren().Play();
}
}
if (MyThrowable != isActiveAndEnabled) { }
else
{
if (MyThrowable.tag == "throwable" && (Input.GetMouseButtonUp(1)))
{
DoThrow();
Hand.GetComponentInChildren<Animation>().Play("Throw");
gameObject.SetActive(false);
}
}
}
And neither of them are throwables (I know I don't need the throwables tag)
Answer by Tripleganger · Feb 09, 2020 at 06:36 PM
It is likely that the problem is with the animation and not with your script.
In your Project window, search for the animation in question.
In your Inspector window, click on Loop Time. If you can't edit it, follow the rest of the steps. Otherwise you should have the animation working as you want.
(Follow only if the animation can't be edited) Duplicate the animation. Select your duplicate and click on Loop Time.
Go to the object that has that animation. If it has an Animation component, then change the old animation with your duplicate. Otherwise, if it has an Animator component, double click it (so the Animator window opens up), click on the state that has the old animation, and replace it with your duplicate.
$$anonymous$$gestions to improve your code. 1 - Use CompareTag("NameOfTag") when comparing tags, ins$$anonymous$$d of other.tag == "NameOfTag". When Unity has in-built functions, it's best to use them. 2 - Ins$$anonymous$$d of using GetComponent functions, make your variables public and assign them via the Inspector, when possible. GetComponent requires more resources than you might think.
I'm pretty sure I won't use the tags since I don't need the tags because I have a script to set damage of weapon throw and I can reference if that is on a game object I'm just using it now so while I'm testing melee I don't conflict code
I can loop it but it still keeps repeating, I also have both an animation and animator if that causes problems (Not sure since this is my first game) i do know that I have to use animator otherwise it won't work Idk if this helps but in the Animator tab there is nothing going to exit (still works fine with my stabbing animation)
So, you want the "Loop Time" checkbox unchecked. Also, your object needs to have either an Animation Component (Which I don't suggest since that object will be bound to play that animation only), OR an Animator component. Hence, what I suggest is to delete the Animation component, keep the Animator component, and check if the Animator is playing the clip with the "Loop Time" checkbox unchecked.
Also, your code mentions the Animation component and not the Animator. So that will need to change. Once you change it, and it is still not working, post your new code here
Nvm It was just me being dumb and not knowing that I imported a folder ins$$anonymous$$d of a sprite xd
Answer by Harrtman · Feb 21, 2020 at 10:23 AM
In PowerPoint, you can control when an animation effect starts and the speed at which it happens. You can even repeat or rewind the effect to get just the right look and feel for your presentation. This article will show you a few ways to fine-tune the animations in your presentations myprepaidcenter activation
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Editing alpha through a script and animation changes the colour not the transparency? 1 Answer
Door animation bugs and stays open unity 3D 0 Answers
3d Animated Jump Script 0 Answers
Animator transition help 0 Answers