前提・実現したいこと
ここに質問の内容を詳しく書いてください。
unity 2017.3of3.personalでc#を用いて指定した軸の動きを制限するコードを書いています。RigitbodyのConstrainsの中にあるfreeze positionの項目をスクリプトで操作をしようとしたが、constraintsの部分がエラーになってしまいました。
発生している問題・エラーメッセージ
エラーメッセージ move.cs(14,14): Error CS1061: Type `UnityEngine.Component' does not contain a definition for `constraints' and no extension method `constraints' of type `UnityEngine.Component' could be found. Are you missing an assembly reference? (CS1061) (Assembly-CSharp)
該当のソースコード
ソースコード using System.Collections; using System.Collections.Generic; using UnityEngine; public class move : MonoBehaviour { int hit = 0; int loopCounter = 0; Vector3 pos; Vector3 pos2; float kurabeX; float kurabeZ; float kurabeX2; float kurabeZ2; // Use this for initialization void Start () { } void OnCollisionEnter (Collision col){ hit = 1; } void OnCollisionExit(Collision col) { hit = 0; } // Update is called once per frame void Update () { loopCounter = loopCounter + 1; if (loopCounter > 2) { loopCounter = 0; } if (loopCounter == 0) { pos = transform.position; } if (loopCounter == 1) { pos2 = transform.position; } if (loopCounter == 2) { kurabeX = pos2.x - pos.x; kurabeZ = pos2.z - pos.z; kurabeX2 = System.Math.Abs (kurabeX); kurabeZ2 = System.Math.Abs (kurabeZ); } if (kurabeZ2 > kurabeX2) { if (kurabeX > 0) { Debug.Log ("moving to +z"); } else { Debug.Log ("moving to -z"); } rigidbody.constraints = RigidbodyConstraints.FreezeRotationX; } if (kurabeX2 > kurabeZ2) { if (kurabeX > 0) { Debug.Log ("moving to +x"); } else { Debug.Log ("moving to -x"); } } if (kurabeX2 == 0 && kurabeZ2 == 0) { Debug.Log("now stopping"); } if (hit == 1) { } } }
補足情報(FW/ツールのバージョンなど)
unity 2017.3of3.personal
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。