- Home /
Animation won't play more than once
I want to get a sprite to play an animation of a drop of liquid falling every time that it is clicked, however the animation only plays the first time I click it and I have no idea why.
Here is the code used on the sprite:
public class PipetteScript : MonoBehaviour {
public Animator pipetteAnim;
public BoxCollider2D pipetteMove;
public IndicatorScript indicator;
// Use this for initialization
void Start () {
pipetteAnim.enabled = true;
pipetteMove.enabled = true;
indicator.enabled = true;
}
void OnMouseDown () {
pipetteAnim.Play ("Pipette_dropping");
Debug.Log ("Anim playing");
}
}
The debug log even prints out "Anim playing" every time I click on the sprite.
Answer by Ekta-Mehta-D · Apr 16, 2015 at 07:41 AM
Hii.. I have one way for playing animation on mouse down.
For that open animator controller and add that dropping animation and one will be ideal animation(this will have initial stage of dropping). Now make ideal animation as default and add transition from ideal to dropping animation.
Add parameter to this transition of type "Trigger". Set this parameter in transition condition.
And add one more transition from dropping animation to ideal state.
So after dropping animation complete , it will come again in ideal state.
Now For scripting :
int dropHash = Animator.StringtoHash("parameterName");
onmouseDown :
animator.SetTrigger(dropHash);
Hope you get some idea. This may help you. Thanks.
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers
How to start an animation by the exit animation frame 0 Answers
2D Animation appears too big on one frame 0 Answers
Getting with the times... learning Mechanim/Animator 1 Answer