質問編集履歴
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,25 +1,80 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
ここに質問の内容を詳しく書いてください。
|
4
|
-
|
4
|
+
unity 2017.3of3.personalでc#を用いて指定した軸の動きを制限するコードを書いています。RigitbodyのConstrainsの中にあるfreeze positionの項目をスクリプトで操作をしようとしたが、constraintsの部分がエラーになってしまいました。
|
5
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
6
|
-
|
7
5
|
### 発生している問題・エラーメッセージ
|
8
|
-
unity 2017.3of3.personalでc#を用いて指定した軸の動きを制限するコードを書いています。RigitbodyのConstrainsの中にあるfreeze positionの項目をスクリプトで操作をしようとしたが、constraintsの部分がエラーになってしまいました。
|
9
6
|
```
|
10
7
|
エラーメッセージ
|
8
|
+
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)
|
11
9
|
```
|
12
|
-
/Volumes/Debetop/VOUNO/Assets/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)
|
13
10
|
### 該当のソースコード
|
14
11
|
|
15
12
|
```ここに言語名を入力
|
16
13
|
ソースコード
|
17
|
-
|
14
|
+
using System.Collections;
|
18
|
-
|
15
|
+
using System.Collections.Generic;
|
19
|
-
|
16
|
+
using UnityEngine;
|
20
17
|
|
18
|
+
public class move : MonoBehaviour {
|
19
|
+
int hit = 0;
|
20
|
+
int loopCounter = 0;
|
21
|
+
Vector3 pos;
|
22
|
+
Vector3 pos2;
|
23
|
+
float kurabeX;
|
24
|
+
float kurabeZ;
|
25
|
+
float kurabeX2;
|
26
|
+
float kurabeZ2;
|
27
|
+
// Use this for initialization
|
28
|
+
void Start () {
|
29
|
+
|
30
|
+
}
|
31
|
+
void OnCollisionEnter (Collision col){
|
32
|
+
hit = 1;
|
33
|
+
}
|
34
|
+
void OnCollisionExit(Collision col) {
|
35
|
+
hit = 0;
|
36
|
+
}
|
37
|
+
// Update is called once per frame
|
38
|
+
void Update () {
|
39
|
+
loopCounter = loopCounter + 1;
|
21
|
-
|
40
|
+
if (loopCounter > 2) {
|
41
|
+
loopCounter = 0;
|
42
|
+
}
|
43
|
+
if (loopCounter == 0) {
|
44
|
+
pos = transform.position;
|
45
|
+
} if (loopCounter == 1) {
|
46
|
+
pos2 = transform.position;
|
47
|
+
}
|
48
|
+
if (loopCounter == 2) {
|
49
|
+
kurabeX = pos2.x - pos.x;
|
50
|
+
kurabeZ = pos2.z - pos.z;
|
51
|
+
kurabeX2 = System.Math.Abs (kurabeX);
|
52
|
+
kurabeZ2 = System.Math.Abs (kurabeZ);
|
53
|
+
}
|
54
|
+
if (kurabeZ2 > kurabeX2) {
|
55
|
+
if (kurabeX > 0) {
|
56
|
+
Debug.Log ("moving to +z");
|
57
|
+
} else {
|
58
|
+
Debug.Log ("moving to -z");
|
59
|
+
}
|
60
|
+
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
|
61
|
+
}
|
62
|
+
if (kurabeX2 > kurabeZ2) {
|
63
|
+
if (kurabeX > 0) {
|
64
|
+
Debug.Log ("moving to +x");
|
65
|
+
} else {
|
66
|
+
Debug.Log ("moving to -x");
|
67
|
+
}
|
68
|
+
}
|
69
|
+
if (kurabeX2 == 0 && kurabeZ2 == 0) {
|
70
|
+
Debug.Log("now stopping");
|
71
|
+
}
|
72
|
+
if (hit == 1) {
|
73
|
+
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
22
77
|
|
78
|
+
```
|
23
79
|
### 補足情報(FW/ツールのバージョンなど)
|
24
|
-
unity 2017.3of3.personal
|
80
|
+
unity 2017.3of3.personal
|
25
|
-
ここにより詳細な情報を記載してください。
|