2017-07-26 103 views
0

我正在使用此腳本銷燬一個gameObject oncomplete,但它不起作用。銷燬gameObject oncomplete

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

有沒有人知道爲什麼這不起作用?

+1

定義'不工作'。 – mjwills

+1

你有調試線? – joreldraw

+0

那麼它不會做任何事情,沒有錯誤,沒有調試。當前立方體掉下來並停在-15。 –

回答

1

從我看到您的腳本未附加到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 
    ) 
); 
+0

謝謝,這工程:)我認爲oncompletetarget必須是應該被摧毀的立方體。我改變了它,所以它銷燬了pastCube,這與跳轉後的currentCube一樣。所以我過去的魔方將會被摧毀,而不是我站立的立方體:) –