0

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?

J.K. Harthoorn
  • 218
  • 1
  • 3
  • 19

1 Answers1

1

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
    )
);
mrogal.ski
  • 5,828
  • 1
  • 21
  • 30
  • Thanks, that works :) I thought the oncompletetarget had to be the cube which should be destroyed. I changed it so it destroys pastCube, which is the same as currentCube AFTER a jump. So that the cube I am past will be destroyed and not the cube i'm standing on :) – J.K. Harthoorn Jul 26 '17 at 11:38