Reputation: 11
I am building a c# unity game and I have encountered some troubles getting my animations to work. I am using LeanTween in order to optain those animations.
Here's some of my code:
void Alpha()
{
Destroy(Cubes[aux]);
AddCube(aux2,Map[aux]);
ChangeColor(aux2);
Map[aux]=0;
Semafor = true;
}
void MoveCube(int Initial,int Final)
{
Semafor = false;
EmptySpaces.Remove(Final);
EmptySpaces.Add (Initial);
LeanTween.move(Cubes[Initial],new Vector3(PosX[Final],PosY[Final],5),0.5f);
aux = Initial; // auxiliar variables used because I don't know how to send params through Invoke
aux2 = Final;
// Invoke( "Alpha",0.6f);
Alpha();
}
If I run the above code like this, without using Invoke it works perfectly. Problem is it destories the GameObject before the animation finishes. Therefore I need some kind of delay between the animation call and the actual call of Destroy. Problem is, the moment I try to use Invoke all functions inside Alpha start acting wierd and buggy. For example, many objects aren't actually destroied.
I am looking for a way to make that function call after a delay. I have tried the yield return new WaitforSeconds
method but it didn't work. Also have tried the LeanTween.delaiedCall
thinggy but it gives me an error when I try passing Alpha because it wants a System.Action.
I am looking for a way to make this animation work and then destroy the object without involving any collision.
Upvotes: 1
Views: 3288
Reputation: 11
You Could make a function which checks the Position of the object!
vector3 finished = null;
GameObject tomove = null;
void update()
{
if(tomove.transform.position == finished)
{
//call your Alpha function
}
}
Its an easy Solution. Also why are you Invoking when the function is in the same File?
Also you have to set the two Parameters when you call the move function.
Upvotes: 1
Reputation: 932
LeanTween docs say to do something like this...
void Alpha()
{
Destroy(Cubes[aux]);
AddCube(aux2,Map[aux]);
ChangeColor(aux2);
Map[aux]=0;
Semafor = true;
}
void MoveCube(int Initial,int Final)
{
Semafor = false;
EmptySpaces.Remove(Final);
EmptySpaces.Add (Initial);
LTDescr d = LeanTween.move(Cubes[Initial],new Vector3(PosX[Final],PosY[Final],5),0.5f);
d.setOnComplete(Alpha);
aux = Initial; // auxiliar variables used because I don't know how to send params through Invoke
aux2 = Final;
}
I cant test this since I dont have lean tween but the docs show what to do here. This should work though.
Upvotes: 1