检测刚体位置(Unity)

时间:2017-08-01 21:51:32

标签: c# unity3d unity5

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

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

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

PlayerController.playerPos 是球体的变换组件 (我也试过用刚体组件来做它并且它既不工作。)

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

2 个答案:

答案 0 :(得分:0)

获取球体的参考。然后得到它的脚本你将获得那个位置不要忘记使用Debug.Log();。如果有效,请告诉我。

答案 1 :(得分:0)

根据您提到的代码,我没有看到任何问题。那很完美。 只需确保将转换分配给您的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);