【发布时间】: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 来确保它:)