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.