Version: 2021.1

Rigidbody.freezeRotation

切换到手册
public bool freezeRotation ;

描述

控制物理是否会更改对象的旋转。

如果启用了 freezeRotation,则物理模拟不会修改旋转。 这对于创建第一人称射击游戏非常有用, 因为玩家需要使用鼠标完全控制旋转。 另请参阅:Rigidbody.constraints

using UnityEngine;

public class Example : MonoBehaviour { Rigidbody m_Rigidbody;

private void Start() { //Fetch the Rigidbody from the GameObject with this script attached m_Rigidbody = GetComponent<Rigidbody>(); //Stop the Rigidbody from rotating m_Rigidbody.freezeRotation = true; } }