我正在学习用 C# 编程,特别是使用 Unity,我遇到了一个问题:
如果球体(带有刚体)通过某个点,例如,如果球体的x位置大于 5 ,我正在尝试移动相机然后移动相机。
相机的移动已完成(带有动画),但位置检测不起作用。我这样做:
if (PlayerController.playerPos.position.x > 5.5f) {
GetComponent<Animator>().SetTrigger ("NextCamera01");
}
PlayerController.playerPos是球体的变换组件
(我也试过用刚体组件来做它,但它也不起作用。)
感谢您的关注,并为我的英语不好而感到抱歉 ;)
根据你上面提到的代码,我没有看到任何问题。那很完美。只需确保将转换分配给您的 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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句