Log in or register to post comments

Wait until animation finish!

June 14, 2011 - 11:25pm #1

Hi there I'm writing an app using Unity extention but I've been stocked a couple of days with Unity animations, basically i want to start an animation at a OnButtonPressed from my Virtual Buttons, and at the end of it i want to do something else

something like:

gameobj.animation.Play("anim");
doSomething();

But the second line is executed before animation finish..

So I have a code calling java methods, something like this:

public void OnButtonPressed(VirtualButtonBehaviour vb)
{
AndroidJavaClass jc = new AndroidJavaClass("com.company.app.class");
AndroidJavaObject jo = jc.GetStatic("currentActivity");
switch (vb.VirtualButtonName)
{
case "btn1":
gameobj.animation.Play("anim");
jo.Call("javamethod");
gameobj.animation.Play("anim2");
break;
}
}

////////////////////////

but my java method is executed immediately, also if I comment that line it would play immediately anim2..

I've tried lots of thing to validate when anim1 finish but none of them have worked for example

while (gameobj.animation.["anim"].time { }
gameobj.animation.Play("anim2");

It would be grate some help on this please :S

Re: Wait until animation finish!

June 15, 2011 - 2:50pm #4

Hi there, thanks for all your help, I've tried those things but you have just give me a key factor, I'm doing this on my VB class maybe I should create a script onto my gameobj and also try placing the condition in the update method so it checks every frame instead of codding directly into my VB class, i will try this out.

thanks a lot

Re: Wait until animation finish!

June 15, 2011 - 7:10am #3

hey,
if i got you right this might be what you are searching for:
http://unity3d.com/support/documentation/ScriptReference/Animation-clip.html
regards,
stefan

Re: Wait until animation finish!

June 15, 2011 - 6:57am #2

You go condition wrong (you would need >=):

while (gameobj.animation.["anim"].time

but it wouldn't work just like that. That would create an infinite loop. Something like that can be done with coroutines (there is something like WaitForNSeconds). Or you could check "gameobj.animation.["anim"].time >= gameobj.animation.["anim"].length" in Update method.

BTW.: you will have more luck by asking Unity question on answers.unity3d.com

Log in or register to post comments