- Home /
How to play and stop animation via code in Unity4.3 for 2D objects.
Hi, I am working on 2D game and I need to animate 2D objects when it collide with others, In Inspector view I unchecked Animator option is not play this on first time. In code first I make this enable "foamObject.GetComponent().enabled = true;" and to play and stop I use this "myObject.animation.Play()" "myObject.animation.Stop()" but this don't work only first time animation is play when I make animator enable. Kindly guide me this is this Unity Issue or I have to do something else to achieve this target. Thanks in advance.
If you show the relevant code that you're using, we would be better able to assist you.
@guitarxe After disabling Animator in Inspector I use this line in Start() method to enabling it. myObject.GetComponent().enabled = true;
and to play animation I use this line to play animation "myObject.animation.Play();" and like this to stop this animation "myObject.animation.Stop();"
@guitarxe can you please guide me any better solution for this, Or if you ever done to play and pause animation for 2D. Thanks