Constraintsの回転をスクリプトから制御する方法をまとめてみました。
移動を制御したい場合はこちらをご覧ください。(_ _)
回転の制御
FreezeRotationX
説明:FreezeRotationX をオンにする。
Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
- サンプルコード
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NewBehaviourScript : MonoBehaviour{
- void Start()
- {
- var rb = GetComponent<Rigidbody>();
- rb.constraints = RigidbodyConstraints.FreezeRotationX;
- }
- }
-------------------------------------------------------------------------------------------------
FreezeRotationY
説明:FreezeRotationY をオンにする。
Rigidbody.constraints = RigidbodyConstraints.FreezeRotationY;
- サンプルコード
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NewBehaviourScript : MonoBehaviour {
- void Start()
- {
- var rb = GetComponent<Rigidbody>();
- rb.constraints = RigidbodyConstraints.FreezeRotationY;
- }
- }
-------------------------------------------------------------------------------------------------
FreezeRotationZ
説明:FreezeRotationZ をオンにする。
Rigidbody.constraints = RigidbodyConstraints.FreezeRotationZ;
- サンプルコード
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NewBehaviourScript : MonoBehaviour {
- void Start()
- {
- var rb = GetComponent<Rigidbody>();
- rb.constraints = RigidbodyConstraints.FreezeRotationZ;
- }
- }
-------------------------------------------------------------------------------------------------
FreezeRotation
説明:FreezeRotationX FreezeRotationY FreezeRotationZをオンにする。
Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
- サンプルコード
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NewBehaviourScript : MonoBehaviour {
- void Start()
- {
- var rb = GetComponent<Rigidbody>();
- rb.constraints = RigidbodyConstraints.FreezeRotation;
- }
- }