質問編集履歴

1

書式の改善

2018/02/24 15:58

投稿

nnnhhh
nnnhhh

スコア8

test CHANGED
File without changes
test CHANGED
@@ -4,23 +4,17 @@
4
4
 
5
5
  ここに質問の内容を詳しく書いてください。
6
6
 
7
- (例)PHP(CakePHP)●●システムを作っていま
7
+ unity 2017.3of3.personalでc#を用いて指定した軸の動きを制限するコードを書いています。RigitbodyのConstrainsの中にあるfreeze positionの項目をスクリプト操作をしようとしたが、constraintsの部分がエラーになってしまいました
8
-
9
- ■■な機能を実装中に以下のエラーメッセージが発生しました。
10
-
11
-
12
8
 
13
9
  ### 発生している問題・エラーメッセージ
14
-
15
- unity 2017.3of3.personalでc#を用いて指定した軸の動きを制限するコードを書いています。RigitbodyのConstrainsの中にあるfreeze positionの項目をスクリプトで操作をしようとしたが、constraintsの部分がエラーになってしまいました。
16
10
 
17
11
  ```
18
12
 
19
13
  エラーメッセージ
20
14
 
15
+ 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)
16
+
21
17
  ```
22
-
23
- /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)
24
18
 
25
19
  ### 該当のソースコード
26
20
 
@@ -30,20 +24,136 @@
30
24
 
31
25
  ソースコード
32
26
 
33
- ```
27
+ using System.Collections;
34
28
 
35
- rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
29
+ using System.Collections.Generic;
36
30
 
37
- ### 試したこと
31
+ using UnityEngine;
38
32
 
39
33
 
40
34
 
35
+ public class move : MonoBehaviour {
36
+
37
+ int hit = 0;
38
+
39
+ int loopCounter = 0;
40
+
41
+ Vector3 pos;
42
+
43
+ Vector3 pos2;
44
+
45
+ float kurabeX;
46
+
47
+ float kurabeZ;
48
+
49
+ float kurabeX2;
50
+
51
+ float kurabeZ2;
52
+
53
+ // Use this for initialization
54
+
55
+ void Start () {
56
+
57
+
58
+
59
+ }
60
+
61
+ void OnCollisionEnter (Collision col){
62
+
63
+ hit = 1;
64
+
65
+ }
66
+
67
+ void OnCollisionExit(Collision col) {
68
+
69
+ hit = 0;
70
+
71
+ }
72
+
73
+ // Update is called once per frame
74
+
75
+ void Update () {
76
+
77
+ loopCounter = loopCounter + 1;
78
+
41
- ここに問題に対して試したことを記載してください。
79
+ if (loopCounter > 2) {
80
+
81
+ loopCounter = 0;
82
+
83
+ }
84
+
85
+ if (loopCounter == 0) {
86
+
87
+ pos = transform.position;
88
+
89
+ } if (loopCounter == 1) {
90
+
91
+ pos2 = transform.position;
92
+
93
+ }
94
+
95
+ if (loopCounter == 2) {
96
+
97
+ kurabeX = pos2.x - pos.x;
98
+
99
+ kurabeZ = pos2.z - pos.z;
100
+
101
+ kurabeX2 = System.Math.Abs (kurabeX);
102
+
103
+ kurabeZ2 = System.Math.Abs (kurabeZ);
104
+
105
+ }
106
+
107
+ if (kurabeZ2 > kurabeX2) {
108
+
109
+ if (kurabeX > 0) {
110
+
111
+ Debug.Log ("moving to +z");
112
+
113
+ } else {
114
+
115
+ Debug.Log ("moving to -z");
116
+
117
+ }
118
+
119
+ rigidbody.constraints = RigidbodyConstraints.FreezeRotationX;
120
+
121
+ }
122
+
123
+ if (kurabeX2 > kurabeZ2) {
124
+
125
+ if (kurabeX > 0) {
126
+
127
+ Debug.Log ("moving to +x");
128
+
129
+ } else {
130
+
131
+ Debug.Log ("moving to -x");
132
+
133
+ }
134
+
135
+ }
136
+
137
+ if (kurabeX2 == 0 && kurabeZ2 == 0) {
138
+
139
+ Debug.Log("now stopping");
140
+
141
+ }
142
+
143
+ if (hit == 1) {
144
+
145
+
146
+
147
+ }
148
+
149
+ }
150
+
151
+ }
42
152
 
43
153
 
154
+
155
+ ```
44
156
 
45
157
  ### 補足情報(FW/ツールのバージョンなど)
46
158
 
47
159
  unity 2017.3of3.personal
48
-
49
- ここにより詳細な情報を記載してください。