Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 完成后销毁游戏对象_C#_Unity3d_Itween - Fatal编程技术网

C# 完成后销毁游戏对象

C# 完成后销毁游戏对象,c#,unity3d,itween,C#,Unity3d,Itween,我正在使用这个脚本在完成时销毁一个游戏对象,但它不起作用 void Jump() { if (currentCube.transform.position.y == 0f) { iTween.MoveTo (currentCube, iTween.Hash ("y", currentCube.transform.position.y - 15f, "time", 0.8f, "oncomplete", "DestroyOnComplete", "oncomple

我正在使用这个脚本在完成时销毁一个游戏对象,但它不起作用

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);
}

有人知道为什么这样做不起作用吗?

据我所知,您的脚本没有连接到currentCube,您正试图在currentCube上调用DestroyOnCompleted。试着这样做:

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
    )
);

定义不起作用。你有调试行吗?它什么都不做,没有错误,没有调试。currentcube确实会崩溃并在-15处停止。您可能需要检查这是否为真:如果currentcube.transform.position.y==0f,请将Debug.Log放入其中。顺便说一下,这样比较浮动不是个好主意。那可能永远不会是真的,我知道你的意思。在这个游戏中,我从未见过它随机变为0.9999999或类似的值,但我将使用Mathf。近似地确保它:谢谢,这是有效的:我认为oncompletetarget必须是应该销毁的立方体。我对它进行了更改,这样它就可以销毁pastCube,这与一次跳转后的currentCube相同。这样我过去的立方体将被摧毁,而不是我站在上面的立方体: