直接上代码吧:
using UnityEngine;
public class test4: MonoBehaviour {
private Rigidbody rb;
private void Awake()
{
rb = gameObject.GetComponent<Rigidbody>();
}
private void Start ()
{
rb.constraints = RigidbodyConstraints.FreezeRotationY;
}
}
下面代码可冻结除本项外其他所有:
rb.constraints = ~RigidbodyConstraints.FreezeRotationY;