質問編集履歴

1

アドバイスをベースにスクリプトを修正

2019/05/07 09:44

投稿

ZaqHaruna
ZaqHaruna

スコア11

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  UI上のObjectが、スクロールで指定のエリアに入ったら、複数のvideoclipからランダムに1つ選んで再生させたいです。
10
10
 
11
- VideoPlayer衝突判定を用いて、特定の1つが再生されるところまではできました。
11
+ Tagで別のObjectからVideoPlayerを取得>衝突判定を用いて、再生まではできました。
12
12
 
13
13
 
14
14
 
@@ -16,27 +16,13 @@
16
16
 
17
17
 
18
18
 
19
+ Tagのものがすべて再生されてしまいます。どれか一つだけにしたいです。
19
20
 
20
-
21
-
22
-
23
- 調べてみて、Tagを使えばいいのか…と思い以下のスクリプトを書いて見ましたがエラーが出て動きません。
24
-
25
-
26
-
27
- 質問1:“複数からランダムに選ぶ”というスクリプトをどのようにかけば良いでしょうか
21
+ 以下のスクリプトをどのように編集すると良いでしょうか
28
-
29
- 質問2:もしTagを使うとしたら、Hierarchyはどのような構造になり、どこにスクリプトを貼り付けると良いでしょうか?
30
22
 
31
23
 
32
24
 
33
25
  宜しくお願い致します。
34
-
35
-
36
-
37
-
38
-
39
- Assets/Script/MoviePlayerRandom.cs(18,6): error CS1525: Unexpected symbol `mPlayerRandom'
40
26
 
41
27
 
42
28
 
@@ -62,19 +48,27 @@
62
48
 
63
49
  public RawImage rImage;
64
50
 
65
- private bool check = false;
51
+ public bool check = false;
66
52
 
67
53
  private GameObject[] videoObjects;
68
54
 
69
55
 
70
56
 
71
-     void Start () {
57
+     void Start ()
58
+
59
+   {
72
60
 
73
61
 
74
62
 
75
- videoObjects = GameObject.FindGameObjectsWithTag ( "VideoRandom" )
63
+ // タグでVideoSourceを持つゲームオブジェクト(複数)を見つける
76
64
 
65
+ videoObjects = GameObject.FindGameObjectsWithTag ( "VideoRandom" );
66
+
67
+ // ”VideoRandom”タグがついたゲームオブジェクトからVideoPlayerを取得
68
+
77
- mPlayerRandom = GetComponent <VideoPlayer> ();
69
+ mPlayerRandom = videoObjects[0].GetComponent <VideoPlayer> ();
70
+
71
+ mPlayerRandom = videoObjects[1].GetComponent <VideoPlayer> ();
78
72
 
79
73
 
80
74
 
@@ -84,41 +78,25 @@
84
78
 
85
79
      void Update ()
86
80
 
87
- {
81
+   {
88
82
 
83
+      // 内部に保存しているテクスチャを設定
89
84
 
85
+      if (mPlayerRandom.texture != null && !check)
90
86
 
91
-         if (VideoRandom.texture != null && !check)
87
+   {
92
88
 
93
- {
89
+       Debug.Log ("Set");
94
90
 
95
-             Debug.Log ("Set");
91
+ // ランダムにオブジェクトを選択
96
92
 
93
+ var VideoRandom = videoObjects[Random.Range(0, videoObjects.Length)];
97
94
 
95
+   rImage.texture = mPlayerRandom.texture;
98
96
 
99
-
97
+   check = true;
100
98
 
101
- var VideoRandom = videoObjects[Random.Range(0, videoObjects.Length)];
102
-
103
-
104
-
105
-
106
-
107
- var videoSourceId = VideoRandom.GetComponent<VideoSourceID>().VideoSourceID;
108
-
109
- print ( videoSourceId );
110
-
111
-
112
-
113
-             rImage.texture = mPlayerRandom.texture;
114
-
115
-
116
-
117
-             check = true;
118
-
119
-
120
-
121
-         }
99
+       }
122
100
 
123
101
          
124
102
 
@@ -126,39 +104,39 @@
126
104
 
127
105
      
128
106
 
129
-
130
-
131
107
  void OnTriggerEnter(Collider other)
132
108
 
133
109
      {
134
110
 
135
-         Debug.Log (other.name + "Enter");
111
+      Debug.Log (other.name + "Enter");
112
+
113
+
136
114
 
137
115
      }
138
116
 
139
117
 
140
118
 
141
-
119
+     // 重なり中の判定
142
120
 
143
121
      void OnTriggerStay(Collider other)
144
122
 
145
123
  {
146
124
 
147
-     {
125
+       {
148
126
 
149
-             Debug.Log (other.name + "Stay");
127
+         Debug.Log (other.name + "Stay");
150
128
 
151
-     }
129
+       }
152
130
 
131
+      //gameObjectがMoviePlayAreaと衝突している場合
153
132
 
133
+   if (other.gameObject.name == "MoviePlayArea")
154
134
 
155
- if (other.gameObject.name == "MoviePlayArea")
135
+       {
156
136
 
157
-             {mPlayerRandom = GetComponent<VideoPlayer>();
137
+ mPlayerRandom.GetComponent<VideoPlayer>().Play();
158
138
 
159
- mPlayerRandom.Play();
160
-
161
- }
139
+ }
162
140
 
163
141
 
164
142
 
@@ -168,25 +146,29 @@
168
146
 
169
147
 
170
148
 
149
+     // 重なり離脱の判定
150
+
171
151
      void OnTriggerExit(Collider other)
172
152
 
173
153
      {
174
154
 
175
-     {
155
+       {
176
156
 
177
157
          Debug.Log (other.name + "Exit");
178
158
 
179
-     }
159
+       }
160
+
161
+
180
162
 
181
163
  if(other.gameObject.name == "MoviePlayArea")
182
164
 
183
-         
165
+         {
184
166
 
185
- {mPlayerRandom = GetComponent<VideoPlayer>();
167
+ mPlayerRandom.GetComponent<VideoPlayer>().Pause();
186
168
 
187
- mPlayerRandom.Pause();
188
169
 
170
+
189
- }
171
+ }
190
172
 
191
173
 
192
174
 
@@ -194,39 +176,9 @@
194
176
 
195
177
      }
196
178
 
197
-
198
-
199
-
200
-
201
179
 
202
180
 
203
181
  }
204
-
205
- ____
206
-
207
-
208
-
209
- using System.Collections;
210
-
211
- using UnityEngine;
212
-
213
- using UnityEngine.Video;
214
-
215
- using UnityEngine.UI;
216
-
217
-
218
-
219
- public class VideoSourceID : MonoBehaviour
220
-
221
- {
222
-
223
- public string VideoSourceID;
224
-
225
- }
226
-
227
-
228
-
229
-
230
182
 
231
183
 
232
184
 
@@ -234,145 +186,11 @@
234
186
 
235
187
 
236
188
 
237
- VideoPlayer衝突判定を用いて、特定の1つが再生されるところまでのスクリプト、ヒエラルキーです。
189
+ Tagで別のObjectからVideoPlayerを取得>衝突判定を用いて、再生までのヒエラルキー
238
190
 
191
+ ![イメージ説明](5d2f940c948ba5f25457067835ab89b7.png)
239
192
 
240
-
241
- using System.Collections;
242
-
243
- using UnityEngine;
244
-
245
- using UnityEngine.Video;
246
-
247
- using UnityEngine.UI;
248
-
249
-
250
-
251
- public class MoviePlayer : MonoBehaviour
252
-
253
- {
254
-
255
- private VideoPlayer mPlayer;
256
-
257
-
258
-
259
- public RawImage rImage;
260
-
261
-
262
-
263
- private bool check = false;
264
-
265
-
266
-
267
-
268
-
269
- void Start () {
270
-
271
- mPlayer = GetComponent <VideoPlayer> ();
272
-
273
- }
274
-
275
-
276
-
277
- void Update ()
278
-
279
- {
280
-
281
-
282
-
283
- if (mPlayer.texture != null && !check)
284
-
285
- {
286
-
287
- Debug.Log ("Set");
288
-
289
- rImage.texture = mPlayer.texture;
290
-
291
- check = true;
292
-
293
- }
294
-
295
-
296
-
297
- }
298
-
299
-
300
-
301
-
302
-
303
- void OnTriggerEnter(Collider other)
304
-
305
-     {
306
-
307
-         Debug.Log (other.name + "Enter");
308
-
309
-     }
310
-
311
-
312
-
313
-     void OnTriggerStay(Collider other)
314
-
315
- {
316
-
317
-     {
318
-
319
-             Debug.Log (other.name + "Stay");
320
-
321
-     }
322
-
323
-  
324
-
325
- if (other.gameObject.name == "MoviePlayArea")
326
-
327
-             {mPlayer = GetComponent<VideoPlayer>();
328
-
329
- mPlayer.Play();
330
-
331
- }
332
-
333
-
334
-
335
-
336
-
337
-     }
338
-
339
-
340
-
341
-     void OnTriggerExit(Collider other)
342
-
343
-     {
344
-
345
-     {
346
-
347
-         Debug.Log (other.name + "Exit");
348
-
349
-     }
350
-
351
- if(other.gameObject.name == "MoviePlayArea")
352
-
353
-         
354
-
355
- {mPlayer = GetComponent<VideoPlayer>();
356
-
357
- mPlayer.Pause();
358
-
359
- }
360
-
361
-
362
-
363
-
364
-
365
-     }
366
-
367
-
368
-
369
-
370
-
371
- }
372
-
373
- ![イメージ説明](f9ee3032b108044fe1ab2559994ff62e.png)
193
+ ![イメージ説明](ab2e1ad44c0fdded210a634524c7a4f0.png)
374
-
375
-
376
194
 
377
195
  ### 補足情報(FW/ツールのバージョンなど)
378
196