Destroy gameObject oncomplete

1.5k Views Asked by At

I am using this script to destroy a gameObject oncomplete, but it doesn't work.

void Jump()
{
    if (currentCube.transform.position.y == 0f) 
    {
        iTween.MoveTo (currentCube, iTween.Hash ("y", currentCube.transform.position.y - 15f, "time", 0.8f, "oncomplete", "DestroyOnComplete", "oncompletetarget", currentCube, "easeType", "easeInCubic", "loopType", "none", "delay", 0));
    }
}

public void DestroyOnComplete()
{   
    Destroy (currentCube);
    Debug.Log ("Destroyed " + currentCube);
}

Does anyone know why this doesn't work?

1

There are 1 best solutions below

1
mrogal.ski On BEST ANSWER

From what I see your script is not attached to currentCube and you're trying to invoke DestroyOnCompleted on currentCube. Try something like this :

iTween.MoveTo (
    currentCube,
    iTween.Hash (
        "y",
        currentCube.transform.position.y - 15f,
        "time",
        0.8f,
        "oncomplete",
        "DestroyOnComplete",
        "oncompletetarget",
        gameObject, // here you had `currentCube`, you can even try with `this` instead
        "easeType",
        "easeInCubic",
        "loopType",
        "none",
        "delay",
        0
    )
);