- Home /
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,
GetComponent(Type type);
or call it
GetComponent<type>();
@Spinnernicholas Thanks and sorry for showing you wrong code I am doing like this as u r suggesting me code. First I disable animator in inspector window and make this enable on to write following line. rubberObject.GetComponent().enabled = true;
It also play animation when I make this enable but I can't play and pause and also stop like this{rubberObject.animation.Play(); rubberObject.animation.Stop();} this when I want this because this play only once, also I again make this disable and then make this enable but It didn't work. $$anonymous$$indly help me on this, if you already done this work for 2D kindly suggest me better way to achieve this target.
Answer by Spinnernicholas · Dec 13, 2013 at 04:24 PM
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. $$anonymous$$indly 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.
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, ins$$anonymous$$d of doing:
animation.Play(animationName);
You will do:
animation.setTrigger(parameterName);
Your answer
Follow this Question
Related Questions
How to play and stop animation via code in Unity4.3 for 2D objects. 0 Answers
SpriteManager 2 1 Answer
App get crash on animation of 2d object in Unity 4.3 0 Answers
A node in a childnode? 1 Answer
Animation and Stealth Tutorial 1 Answer