Animation is not playing again in Unity 4.3

Hi I have a 2D object in which I added Animation and in Animation disable Loop time, also make disable animator with my game object is just to play when I needed. Below line is call on start function.

rubberObject.GetComponent().enabled = false;

and play this it hits some other object in on enter collider2D function.

rubberObject.GetComponent().enabled = true;

and then disable it on exit collider2D function again. It works fine for first time but when it collider again with object it doesn’t animate, the same functionality applied on second time but it doesn’t animate. I don’t know why this happen is this Unity issue or on my side Issue. Kindly help me on this. Thanks in advance.

So what, you have an animation that is supposed to play during a collision? Any more information you can give will help. Also, you need to pass a type to [GetComponent][1], GetComponent(Type type); or call it GetComponent<type>(); [1]: http://docs.unity3d.com/Documentation/ScriptReference/Component.GetComponent.html

1 Answer

1

If you are using sprite(dope sheet) animation, it was built to use the Animator component and doesn’t work as expected with the Animation component. If all of your animations are animation curves, then this doesn’t apply to you.

@Spinnernicholas I am using sprite animation, so What I have to do to play and stop animation when I want this. I only have to images sprite animation. Kindly suggest me better way to accomplish this task.

You will have to use the animator component. You can simulate the same functionality of the animation component. See [HERE][1]. - Create a parameter for each animation. - Then create a state for each animation and set the animation in it. - Create a transition from the any state to each animation state and set the transition condition as the parameters you made earlier. Now, instead of doing: animation.Play(animationName); You will do: animation.setTrigger(parameterName); [1]: http://docs.unity3d.com/Documentation/Manual/Animator.html

How's it going?