检测刚体位置 (Unity)

Detect a Rigidbody position (Unity)

我正在学习使用 C# 编程,特别是使用 Unity,我遇到了一个问题:
如果球体(带有刚体)通过某个点,我会尝试移动相机,例如,如果球体的 x 位置大于 5,则移动相机。

相机的移动已经完成(带有动画),但位置检测不起作用。我这样做:

if (PlayerController.playerPos.position.x > 5.5f) {
    GetComponent<Animator>().SetTrigger ("NextCamera01");
}

PlayerController.playerPos是球体的变换分量
(我也试过用刚体组件来做,但它都不起作用。)

感谢您的关注,抱歉我的英语不好 ;)

获取球体的引用。然后得到它的脚本你会得到那个位置不要忘记使用 Debug.Log();。让我知道它是否有效。

根据您上面提到的代码,我没有发现任何问题。那很完美。 只需确保将转换分配给您的 playerPos 变量并尝试 Debug.Log 使用该代码,例如..

    if (PlayerController.playerPos.position.x > 5.5f)
        Debug.Log ("Trigger action at player pos " + PlayerController.playerPos.position.x);
    else
        Debug.Log ("Wait for player pos " + PlayerController.playerPos.position.x);