【问题标题】:Destroy gameObject oncomplete在完成时销毁游戏对象
【发布时间】:2018-01-01 15:41:41
【问题描述】:

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

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

有谁知道为什么这不起作用?

【问题讨论】:

  • 定义doesn't work。
  • 你有调试线吗?
  • 好吧,它什么也没做,没有错误,没有调试。 currentcube 确实会掉下来并在 -15 处停止。
  • 您可能想要检查这是否属实:if (currentCube.transform.position.y == 0f) 将Debug.Log 放入其中。顺便说一句,像这样比较浮动并不是一个好主意。这可能永远不会是真的。
  • 我知道你的意思。在这个游戏中,我从未见过它随机变为 0.9999999 或类似的东西,但我会使用 Mathf.Approximately 来确保它:)

标签: c# unity3d itween


【解决方案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
    )
);

【讨论】:

  • 谢谢,这行得通 :) 我认为 oncompletetarget 必须是应该被销毁的立方体。我对其进行了更改,因此它破坏了 pastCube,这与跳跃后的 currentCube 相同。这样我过去的立方体将被摧毁,而不是我站立的立方体:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 2012-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多