質問編集履歴

1

スクリプトの追加

2018/12/21 08:43

投稿

rinkis
rinkis

スコア13

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,277 @@
21
21
  それか他に良い判定の作り方があれば教えていただければと思います。
22
22
 
23
23
  中傷はきついっす。
24
+
25
+
26
+
27
+ 【補足】
28
+
29
+ 現在はMIDIファイルを使って音ゲーを制作しています。
30
+
31
+ ノーツが流れるレーンは一つです。
32
+
33
+ SmfLiteというソースを参考にして、スクリプトを作りました。
34
+
35
+
36
+
37
+ 譜面スクリプト
38
+
39
+
40
+
41
+ using UnityEngine;
42
+
43
+ using System.Collections;
44
+
45
+ using System.Collections.Generic;
46
+
47
+ using SmfLite;
48
+
49
+
50
+
51
+ public class Tester : MonoBehaviour
52
+
53
+ {
54
+
55
+ // Source MIDI file asset.
56
+
57
+ public TextAsset sourceFile;
58
+
59
+
60
+
61
+ // Test settings.
62
+
63
+ public float bpm;
64
+
65
+
66
+
67
+ public GameObject o36;
68
+
69
+ public GameObject o37;
70
+
71
+ public GameObject o38;
72
+
73
+ public GameObject o39;
74
+
75
+ public GameObject o40;
76
+
77
+
78
+
79
+
80
+
81
+ // MIDI objects.
82
+
83
+ MidiFileContainer song;
84
+
85
+ MidiTrackSequencer sequencer;
86
+
87
+
88
+
89
+ // Start function (MonoBehaviour).
90
+
91
+ IEnumerator Start ()
92
+
93
+ {
94
+
95
+ // Load the MIDI song.
96
+
97
+ song = MidiFileLoader.Load (sourceFile.bytes);
98
+
99
+
100
+
101
+ var tempo = 120f; // テンポはすでに読み込み済みとする
102
+
103
+
104
+
105
+ // Wait for one second to avoid stuttering.
106
+
107
+ yield return new WaitForSeconds (1.0f);
108
+
109
+
110
+
111
+ // Start sequencing.
112
+
113
+ ResetAndPlay (0);
114
+
115
+ }
116
+
117
+
118
+
119
+ // Reset and start sequecing.
120
+
121
+ void ResetAndPlay (float startTime)
122
+
123
+ {
124
+
125
+ // Play the audio clip.
126
+
127
+ // audio.Play ();
128
+
129
+ // audio.time = startTime;
130
+
131
+
132
+
133
+ // Start the sequencer and dispatch events at the beginning of the track.
134
+
135
+ sequencer = new MidiTrackSequencer (song.tracks [1], song.division, bpm);
136
+
137
+ DispatchEvents (sequencer.Start (startTime));
138
+
139
+ }
140
+
141
+
142
+
143
+ // Update function (MonoBehaviour).
144
+
145
+ void Update ()
146
+
147
+ {
148
+
149
+ if (sequencer != null && sequencer.Playing) {
150
+
151
+ // Update the sequencer and dispatch incoming events.
152
+
153
+ DispatchEvents (sequencer.Advance (Time.deltaTime));
154
+
155
+ }
156
+
157
+ }
158
+
159
+
160
+
161
+ // Dispatch incoming MIDI events.
162
+
163
+ void DispatchEvents (List<MidiEvent> events)
164
+
165
+ {
166
+
167
+
168
+
169
+ if (events != null) {
170
+
171
+ foreach (var e in events) {
172
+
173
+ if ((e.status & 0xf0) == 0x90) {
174
+
175
+ Debug.Log (e.data1);
176
+
177
+ if (e.data1 == 44) {
178
+
179
+ Instantiate (o36);
180
+
181
+ //イントロ
182
+
183
+ //ノーツをずらす方法
184
+
185
+ }
186
+
187
+ if (e.data1 == 43) {
188
+
189
+ Instantiate (o37);
190
+
191
+ //イントロ
192
+
193
+ }
194
+
195
+ if (e.data1 == 41) {
196
+
197
+ Instantiate (o38);
198
+
199
+ //イントロ
200
+
201
+ }
202
+
203
+ if (e.data1 == 24) {
204
+
205
+ Instantiate (o40);
206
+
207
+ //jamp
208
+
209
+ }
210
+
211
+ if (e.data1 == 48) {
212
+
213
+ Instantiate (o39);
214
+
215
+ }
216
+
217
+ //仮の譜面
218
+
219
+ }
220
+
221
+ }
222
+
223
+ }
224
+
225
+ }
226
+
227
+ }
228
+
229
+
230
+
231
+
232
+
233
+ ノーツスクリプト
234
+
235
+ using System.Collections;
236
+
237
+ using System.Collections.Generic;
238
+
239
+ using UnityEngine;
240
+
241
+
242
+
243
+ public class Notes : MonoBehaviour {
244
+
245
+
246
+
247
+ public float lifetime;
248
+
249
+ public GameObject o1;
250
+
251
+ public float vector;
252
+
253
+
254
+
255
+ // Use this for initialization
256
+
257
+ void Start () {
258
+
259
+
260
+
261
+ Destroy(gameObject, lifetime);
262
+
263
+
264
+
265
+ }
266
+
267
+
268
+
269
+ // Update is called once per frame
270
+
271
+ void Update () {//ノーツの移動(仮)
272
+
273
+
274
+
275
+ //等速アニメーション
276
+
277
+ this.transform.position += new Vector3(0, 0, vector);
278
+
279
+ }
280
+
281
+ void OnTriggerStay(Collider colobj)//範囲内、右矢印キーを押すとノーツがデリートされる。
282
+
283
+ {
284
+
285
+ if (Input.GetKeyDown (KeyCode.RightArrow)) {
286
+
287
+ Destroy (this.o1);
288
+
289
+ }
290
+
291
+ }
292
+
293
+ }
294
+
295
+
296
+
297
+ Destroyしているのですがなぜかノーツは消えてくれない状況に陥っています。