teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

9

a

2020/04/20 15:11

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -47,8 +47,13 @@
47
47
 
48
48
 
49
49
  }
50
+
51
+ ```
52
+
50
53
  OniController
54
+
51
55
  ```C#
56
+
52
57
  using System.Collections;
53
58
  using System.Collections.Generic;
54
59
  using UnityEngine;
@@ -131,4 +136,5 @@
131
136
  }
132
137
 
133
138
 
139
+
134
140
  ```

8

miss

2020/04/20 15:10

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -130,4 +130,5 @@
130
130
 
131
131
  }
132
132
 
133
+
133
134
  ```

7

スクリプトの追加

2020/04/20 15:09

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
@@ -1,1 +1,1 @@
1
- unity3D 捕まったレイヤー待機場所実装
1
+ unity3D スクリboolが全て複数オブジェクトに反映されてしまう。
body CHANGED
@@ -1,256 +1,82 @@
1
- unity3Dで鬼ごっこゲームを作ます。
1
+ unity3d鬼ごっこゲームを作成しおります。
2
2
 
3
+ プレイヤーと鬼を2対ずつ用意をしているのですが、鬼が1対のプレイヤーを捕まえた際にプレイヤーが二体とも捕まってしまうようになってしまいます。
3
- プレイヤーと選ん遊べるゲームです。
4
+ プレイヤーにboolの判定分けたい場合どのようにすれば良いかアドバイスをいただけますと幸いです。
4
5
 
5
- プレイヤーを操作する際、鬼に捕まった場合は指定した座標にtransform.positionで送るように設定をしており、その四方に空のオブジェクトを生成し、ボックスコライダーで壁を作ることで牢屋を生成し、プレイヤーの動きをその範囲内でしか行動できないようにしており、
6
- 他のプレイヤーが助けにきた際に施錠できるようにするために牢屋の外側の四方に空のオブジェクトを作成しているのですが、鬼を操作した際にその牢屋の四方の内部が移動できない状態になってしまいます。(円とライトで牢屋を作成しているのでその中も動けるようにしたいと考えております。)
7
6
 
7
+ 下記にスクリプトを追加させていただきました。
8
- 解決方法として1つの大きなボックスコライダーをアタッチし、OncolisionStayでの実装をしようとししたが、
8
+ PlayerController,OniControllerでの実装をしておりす。
9
- 他のプレイヤーがその範囲入っみ解錠できようにしたいので空のオブジェクトにボックスコライダーを一つアタッチし範囲を設定したはプレイヤーが内部から解錠できてしまうので、実装方法に悩んでおります。
9
+ 鬼がプレイヤーに近付いらそプレイヤーが捕獲されるにしたいと考えております。(実際は他のプレイヤーも所定の場所に飛ばされてしまます。
10
10
 
11
- プレイヤーにはPlayerタグ、鬼にはoniタグをつけて判定を行なっております。
12
11
 
13
- どなたかアドバイスをいただけますと幸いです。
12
+ PlayerScripts
14
-
15
13
  ```C#
16
14
  using System.Collections;
17
15
  using System.Collections.Generic;
18
16
  using UnityEngine;
19
-
20
- public class GameController : MonoBehaviour
21
- {
22
- public GameObject ButtonKaiho;
23
- public GameObject Rouya;
24
- //プレイヤーの取得
25
- GameObject Player;
26
-
27
- //スクリプトの取得
28
- public PlayerController PlayerControllerScript;
29
- public RouyaScript RouyaScript;
30
-
31
-
32
-
33
- void Start()
34
- {
35
- //プレイヤーの取得
36
- this.Player = GameObject.Find("Player");
37
- }
38
-
39
- void Update()
40
- {
41
-
42
- //他のプレイヤーのロック解放
43
- if (Rouya.GetComponent<RouyaScript>().ishelp == true)
44
- {
45
- ButtonKaiho.SetActive(true);
46
-
47
- }
48
- else
49
- {
50
- ButtonKaiho.SetActive(false);
51
-
52
- }
53
- }
54
-
55
- public void OnButtonKaiho()
56
- {
57
- Rouya.SetActive(false);
58
- Debug.Log("牢屋消えた");
59
-
60
- Player.GetComponent<OniController>().isCaptured = false;
61
- Debug.Log("プレイヤー捕まってない状態");
62
- Rouya.GetComponent<RouyaScript>().ishelp = false;
63
- Debug.Log("助ける状態のリセット");
64
- }
65
- }
66
-
67
- ```
68
- ```C#
69
- using System.Collections;
70
- using System.Collections.Generic;
71
- using UnityEngine;
72
-
73
- public class RouyaScript : MonoBehaviour
74
- {
75
- //プレイヤーの取得
76
- GameObject Player;
77
- public bool ishelp;
78
-
79
-
80
- // Start is called before the first frame update
81
- void Start()
82
- {
83
-      //プレイヤーの取得
84
- this.Player = GameObject.Find("Player");
85
-
86
- }
87
-
88
-
89
- //牢屋にプレイヤーが触れた場合
90
- public void OnCollisionEnter(Collision hit)
91
- {
92
- if (hit.gameObject.tag == "Player")
93
-
94
- if (Player.GetComponent<PlayerController>().isCaptured == false)
95
- {
96
-
97
-
98
- Help();
99
-
100
- }
101
- }
102
-
103
- void Help()
104
- {
105
- ishelp = true;
106
-
107
- }
108
-
109
-
110
-
111
- }
112
-
113
-
114
-
115
- ```
116
- ```C#
117
- using System.Collections;
118
- using System.Collections.Generic;
119
- using UnityEngine;
120
17
  using UnityEngine.UI;
121
18
 
122
19
  public class PlayerController : MonoBehaviour
123
20
  {
124
- //プレイヤーにアタッチされている足の速さを決めるスクリプト
125
- [SerializeField] private UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter anotherScript;
21
+ [SerializeField] public OniController anotherScript1;
126
22
 
127
- void Start()
23
+    void Start()
128
24
  {
129
25
 
130
26
 
131
27
  anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>();
132
28
 
29
+ GameObject anotherObject = GameObject.FindWithTag("Oni");
30
+ anotherScript1 = anotherObject.GetComponent<OniController>();
133
31
 
134
32
 
135
33
  }
136
34
 
137
35
  void Update()
138
36
  {
139
- if (isCaptured == true)
37
+ if (anotherScript1.isRouya == true)
140
38
  {
141
- //捕まっている場合は0
39
+ float rouya_y = 1.5f;
142
- SetValue(0);
143
- }
144
40
 
145
- if (isCaptured == false)
41
+ transform.position = new Vector3(65, rouya_y, 65);
146
- {
147
- SetValue(2);
148
- }
149
42
 
150
- }
151
-
152
-
153
- public void OnTriggerStay(Collider hit)
154
- {
155
- // 牢屋に触れた場合
156
-
157
- if (hit.gameObject.tag == "Rouya")
158
- {
159
-
160
- Captured();
161
-
162
43
  }
163
-
164
-
165
44
  }
166
45
 
167
46
 
168
- void SetValue(int value)
47
+
169
- {
170
- anotherScript.M_MoveSpeedMultiplier = value;
171
48
 
172
- //Debug.Log("M_MoveSpeedMultiplie = " + anotherScript.M_MoveSpeedMultiplier);
173
- }
174
-
175
- public void Captured()
176
- {
177
- isCaptured = true;
178
- }
179
-
180
-
181
-
182
-
183
-
184
49
  }
185
-
186
-
187
- ```
188
- 鬼のスクリプトのみ抜粋いたしました。
50
+ OniController
189
51
  ```C#
190
52
  using System.Collections;
191
53
  using System.Collections.Generic;
192
54
  using UnityEngine;
193
55
  using UnityEngine.UI;
194
56
 
195
- public class GameController : MonoBehaviour
57
+ public class OniController : MonoBehaviour
196
58
  {
59
+ //プレイヤーの取得
197
- List<GameObject> Oni = new List<GameObject>();
60
+ List<GameObject> Players = new List<GameObject>();
198
61
 
62
+ public bool isRouya;
199
63
 
200
- void Start()
64
+
201
- {
202
-
203
-
204
- Onis.AddRange(GameObject.FindGameObjectsWithTag("Oni"));
205
65
 
66
+ [SerializeField] private Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
206
67
 
207
- }
208
68
 
209
69
 
210
- void Update()
70
+ void Start()
211
71
  {
212
- foreach (GameObject oni in Onis)
72
+ //プレイヤーの取得
213
- {
214
- //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisHokakuの部分にエラーが出て不可能でした。
215
- if (oni.GetComponents<PoliceController>().isHokaku == true)
73
+ Players.AddRange(GameObject.FindGameObjectsWithTag("Player"));
216
- {
217
- Rouya.SetActive(true);
218
74
 
219
- }
220
- else
221
- {
222
- Rouya.SetActive(false);
75
+ anotherScript = GetComponent<Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter>();
223
76
 
224
- }
225
77
 
226
- }
227
- }
228
78
 
229
79
 
230
- ```
231
-
232
- ```C#
233
- using System.Collections;
234
- using System.Collections.Generic;
235
- using UnityEngine;
236
- using UnityEngine.UI;
237
-
238
- public class OniController : MonoBehaviour
239
- {
240
- GameObject Player;
241
- public bool isHokaku;
242
-
243
- [SerializeField] private Police.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
244
-
245
-
246
-
247
-
248
- void Start()
249
- {
250
- this.Player = GameObject.Find("Player");
251
- anotherScript = GetComponent<Police.UnityStandardAssets.Characters.ThirdPerson.Police_ThirdPersonCharacter>();
252
-
253
-
254
80
  }
255
81
 
256
82
 
@@ -260,38 +86,48 @@
260
86
  if (hit.gameObject.tag == "Player")
261
87
  {
262
88
  //Debug.Log("プレイヤーと接触している");
89
+
263
- OnButtonHokaku();
90
+ OnButtonHokaku();
264
-
91
+
265
92
  }
266
-
93
+
267
94
  }
268
95
 
269
96
  public void OnButtonHokaku()
270
97
  {
271
98
 
272
-
99
+
100
+
101
+
273
- Invoke("Hokaku", 0.7f);
102
+ Invoke("Rouya", 0.7f);
274
103
  anotherScript.TouchStart();
275
104
  Invoke("OnTouchEnd", 0.5f);
276
105
 
106
+
277
107
 
278
108
 
279
109
 
110
+
111
+
280
112
  }
281
- public void Hokaku()
113
+ public void Rouya()
282
114
  {
115
+
116
+
283
- isHokaku = true;
117
+ isRouya = true;
284
- float rouya_y = 1.5f;
285
- this.Player.transform.position = new Vector3(65, rouya_y, 65);
286
118
 
119
+
120
+
287
121
  }
288
-
122
+ //アニメーションです。
289
123
  public void OnTouchEnd()
290
124
  {
291
125
  anotherScript.TouchEnd();
292
126
  }
293
127
 
128
+
294
129
 
295
130
 
296
131
  }
132
+
297
133
  ```

6

a

2020/04/20 15:04

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -57,7 +57,7 @@
57
57
  Rouya.SetActive(false);
58
58
  Debug.Log("牢屋消えた");
59
59
 
60
- Player.GetComponent<PlayerController>().isCaptured = false;
60
+ Player.GetComponent<OniController>().isCaptured = false;
61
61
  Debug.Log("プレイヤー捕まってない状態");
62
62
  Rouya.GetComponent<RouyaScript>().ishelp = false;
63
63
  Debug.Log("助ける状態のリセット");

5

a

2020/04/20 09:59

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -227,4 +227,71 @@
227
227
  }
228
228
 
229
229
 
230
+ ```
231
+
232
+ ```C#
233
+ using System.Collections;
234
+ using System.Collections.Generic;
235
+ using UnityEngine;
236
+ using UnityEngine.UI;
237
+
238
+ public class OniController : MonoBehaviour
239
+ {
240
+ GameObject Player;
241
+ public bool isHokaku;
242
+
243
+ [SerializeField] private Police.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
244
+
245
+
246
+
247
+
248
+ void Start()
249
+ {
250
+ this.Player = GameObject.Find("Player");
251
+ anotherScript = GetComponent<Police.UnityStandardAssets.Characters.ThirdPerson.Police_ThirdPersonCharacter>();
252
+
253
+
254
+ }
255
+
256
+
257
+ public void OnCollisionStay(Collision hit)
258
+ {
259
+ // 接触対象はPlayerタグですか?
260
+ if (hit.gameObject.tag == "Player")
261
+ {
262
+ //Debug.Log("プレイヤーと接触している");
263
+ OnButtonHokaku();
264
+
265
+ }
266
+
267
+ }
268
+
269
+ public void OnButtonHokaku()
270
+ {
271
+
272
+
273
+ Invoke("Hokaku", 0.7f);
274
+ anotherScript.TouchStart();
275
+ Invoke("OnTouchEnd", 0.5f);
276
+
277
+
278
+
279
+
280
+ }
281
+ public void Hokaku()
282
+ {
283
+ isHokaku = true;
284
+ float rouya_y = 1.5f;
285
+ this.Player.transform.position = new Vector3(65, rouya_y, 65);
286
+
287
+ }
288
+
289
+ public void OnTouchEnd()
290
+ {
291
+ anotherScript.TouchEnd();
292
+ }
293
+
294
+
295
+
296
+ }
230
297
  ```

4

a

2020/04/20 09:58

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -211,7 +211,7 @@
211
211
  {
212
212
  foreach (GameObject oni in Onis)
213
213
  {
214
- //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisTaihoの部分にエラーが出て不可能でした。
214
+ //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisHokakuの部分にエラーが出て不可能でした。
215
215
  if (oni.GetComponents<PoliceController>().isHokaku == true)
216
216
  {
217
217
  Rouya.SetActive(true);

3

add

2020/04/20 09:52

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -184,4 +184,47 @@
184
184
  }
185
185
 
186
186
 
187
+ ```
188
+ 鬼のスクリプトのみ抜粋いたしました。
189
+ ```C#
190
+ using System.Collections;
191
+ using System.Collections.Generic;
192
+ using UnityEngine;
193
+ using UnityEngine.UI;
194
+
195
+ public class GameController : MonoBehaviour
196
+ {
197
+ List<GameObject> Oni = new List<GameObject>();
198
+
199
+
200
+ void Start()
201
+ {
202
+
203
+
204
+ Onis.AddRange(GameObject.FindGameObjectsWithTag("Oni"));
205
+
206
+
207
+ }
208
+
209
+
210
+ void Update()
211
+ {
212
+ foreach (GameObject oni in Onis)
213
+ {
214
+ //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisTaihoの部分にエラーが出て不可能でした。
215
+ if (oni.GetComponents<PoliceController>().isHokaku == true)
216
+ {
217
+ Rouya.SetActive(true);
218
+
219
+ }
220
+ else
221
+ {
222
+ Rouya.SetActive(false);
223
+
224
+ }
225
+
226
+ }
227
+ }
228
+
229
+
187
230
  ```

2

add

2020/04/20 01:54

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
File without changes
body CHANGED
@@ -10,4 +10,178 @@
10
10
 
11
11
  プレイヤーにはPlayerタグ、鬼にはoniタグをつけて判定を行なっております。
12
12
 
13
- どなたかアドバイスをいただけますと幸いです。
13
+ どなたかアドバイスをいただけますと幸いです。
14
+
15
+ ```C#
16
+ using System.Collections;
17
+ using System.Collections.Generic;
18
+ using UnityEngine;
19
+
20
+ public class GameController : MonoBehaviour
21
+ {
22
+ public GameObject ButtonKaiho;
23
+ public GameObject Rouya;
24
+ //プレイヤーの取得
25
+ GameObject Player;
26
+
27
+ //スクリプトの取得
28
+ public PlayerController PlayerControllerScript;
29
+ public RouyaScript RouyaScript;
30
+
31
+
32
+
33
+ void Start()
34
+ {
35
+ //プレイヤーの取得
36
+ this.Player = GameObject.Find("Player");
37
+ }
38
+
39
+ void Update()
40
+ {
41
+
42
+ //他のプレイヤーのロック解放
43
+ if (Rouya.GetComponent<RouyaScript>().ishelp == true)
44
+ {
45
+ ButtonKaiho.SetActive(true);
46
+
47
+ }
48
+ else
49
+ {
50
+ ButtonKaiho.SetActive(false);
51
+
52
+ }
53
+ }
54
+
55
+ public void OnButtonKaiho()
56
+ {
57
+ Rouya.SetActive(false);
58
+ Debug.Log("牢屋消えた");
59
+
60
+ Player.GetComponent<PlayerController>().isCaptured = false;
61
+ Debug.Log("プレイヤー捕まってない状態");
62
+ Rouya.GetComponent<RouyaScript>().ishelp = false;
63
+ Debug.Log("助ける状態のリセット");
64
+ }
65
+ }
66
+
67
+ ```
68
+ ```C#
69
+ using System.Collections;
70
+ using System.Collections.Generic;
71
+ using UnityEngine;
72
+
73
+ public class RouyaScript : MonoBehaviour
74
+ {
75
+ //プレイヤーの取得
76
+ GameObject Player;
77
+ public bool ishelp;
78
+
79
+
80
+ // Start is called before the first frame update
81
+ void Start()
82
+ {
83
+      //プレイヤーの取得
84
+ this.Player = GameObject.Find("Player");
85
+
86
+ }
87
+
88
+
89
+ //牢屋にプレイヤーが触れた場合
90
+ public void OnCollisionEnter(Collision hit)
91
+ {
92
+ if (hit.gameObject.tag == "Player")
93
+
94
+ if (Player.GetComponent<PlayerController>().isCaptured == false)
95
+ {
96
+
97
+
98
+ Help();
99
+
100
+ }
101
+ }
102
+
103
+ void Help()
104
+ {
105
+ ishelp = true;
106
+
107
+ }
108
+
109
+
110
+
111
+ }
112
+
113
+
114
+
115
+ ```
116
+ ```C#
117
+ using System.Collections;
118
+ using System.Collections.Generic;
119
+ using UnityEngine;
120
+ using UnityEngine.UI;
121
+
122
+ public class PlayerController : MonoBehaviour
123
+ {
124
+ //プレイヤーにアタッチされている足の速さを決めるスクリプト
125
+ [SerializeField] private UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter anotherScript;
126
+
127
+ void Start()
128
+ {
129
+
130
+
131
+ anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>();
132
+
133
+
134
+
135
+ }
136
+
137
+ void Update()
138
+ {
139
+ if (isCaptured == true)
140
+ {
141
+ //捕まっている場合は0
142
+ SetValue(0);
143
+ }
144
+
145
+ if (isCaptured == false)
146
+ {
147
+ SetValue(2);
148
+ }
149
+
150
+ }
151
+
152
+
153
+ public void OnTriggerStay(Collider hit)
154
+ {
155
+ // 牢屋に触れた場合
156
+
157
+ if (hit.gameObject.tag == "Rouya")
158
+ {
159
+
160
+ Captured();
161
+
162
+ }
163
+
164
+
165
+ }
166
+
167
+
168
+ void SetValue(int value)
169
+ {
170
+ anotherScript.M_MoveSpeedMultiplier = value;
171
+
172
+ //Debug.Log("M_MoveSpeedMultiplie = " + anotherScript.M_MoveSpeedMultiplier);
173
+ }
174
+
175
+ public void Captured()
176
+ {
177
+ isCaptured = true;
178
+ }
179
+
180
+
181
+
182
+
183
+
184
+ }
185
+
186
+
187
+ ```

1

miss

2020/04/19 07:14

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

title CHANGED
@@ -1,1 +1,1 @@
1
- unity3D 捕まった場所の待機場所の実装
1
+ unity3D 捕まったプレイヤーの待機場所の実装
body CHANGED
File without changes