質問編集履歴

1

スクリプトの追加

2018/12/21 08:43

投稿

rinkis
rinkis

スコア13

title CHANGED
File without changes
body CHANGED
@@ -9,4 +9,141 @@
9
9
  この中だとすべてのボックスコライダに適用されてしまうので…
10
10
 
11
11
  それか他に良い判定の作り方があれば教えていただければと思います。
12
- 中傷はきついっす。
12
+ 中傷はきついっす。
13
+
14
+ 【補足】
15
+ 現在はMIDIファイルを使って音ゲーを制作しています。
16
+ ノーツが流れるレーンは一つです。
17
+ SmfLiteというソースを参考にして、スクリプトを作りました。
18
+
19
+ 譜面スクリプト
20
+
21
+ using UnityEngine;
22
+ using System.Collections;
23
+ using System.Collections.Generic;
24
+ using SmfLite;
25
+
26
+ public class Tester : MonoBehaviour
27
+ {
28
+ // Source MIDI file asset.
29
+ public TextAsset sourceFile;
30
+
31
+ // Test settings.
32
+ public float bpm;
33
+
34
+ public GameObject o36;
35
+ public GameObject o37;
36
+ public GameObject o38;
37
+ public GameObject o39;
38
+ public GameObject o40;
39
+
40
+
41
+ // MIDI objects.
42
+ MidiFileContainer song;
43
+ MidiTrackSequencer sequencer;
44
+
45
+ // Start function (MonoBehaviour).
46
+ IEnumerator Start ()
47
+ {
48
+ // Load the MIDI song.
49
+ song = MidiFileLoader.Load (sourceFile.bytes);
50
+
51
+ var tempo = 120f; // テンポはすでに読み込み済みとする
52
+
53
+ // Wait for one second to avoid stuttering.
54
+ yield return new WaitForSeconds (1.0f);
55
+
56
+ // Start sequencing.
57
+ ResetAndPlay (0);
58
+ }
59
+
60
+ // Reset and start sequecing.
61
+ void ResetAndPlay (float startTime)
62
+ {
63
+ // Play the audio clip.
64
+ // audio.Play ();
65
+ // audio.time = startTime;
66
+
67
+ // Start the sequencer and dispatch events at the beginning of the track.
68
+ sequencer = new MidiTrackSequencer (song.tracks [1], song.division, bpm);
69
+ DispatchEvents (sequencer.Start (startTime));
70
+ }
71
+
72
+ // Update function (MonoBehaviour).
73
+ void Update ()
74
+ {
75
+ if (sequencer != null && sequencer.Playing) {
76
+ // Update the sequencer and dispatch incoming events.
77
+ DispatchEvents (sequencer.Advance (Time.deltaTime));
78
+ }
79
+ }
80
+
81
+ // Dispatch incoming MIDI events.
82
+ void DispatchEvents (List<MidiEvent> events)
83
+ {
84
+
85
+ if (events != null) {
86
+ foreach (var e in events) {
87
+ if ((e.status & 0xf0) == 0x90) {
88
+ Debug.Log (e.data1);
89
+ if (e.data1 == 44) {
90
+ Instantiate (o36);
91
+ //イントロ
92
+ //ノーツをずらす方法
93
+ }
94
+ if (e.data1 == 43) {
95
+ Instantiate (o37);
96
+ //イントロ
97
+ }
98
+ if (e.data1 == 41) {
99
+ Instantiate (o38);
100
+ //イントロ
101
+ }
102
+ if (e.data1 == 24) {
103
+ Instantiate (o40);
104
+ //jamp
105
+ }
106
+ if (e.data1 == 48) {
107
+ Instantiate (o39);
108
+ }
109
+ //仮の譜面
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+
117
+ ノーツスクリプト
118
+ using System.Collections;
119
+ using System.Collections.Generic;
120
+ using UnityEngine;
121
+
122
+ public class Notes : MonoBehaviour {
123
+
124
+ public float lifetime;
125
+ public GameObject o1;
126
+ public float vector;
127
+
128
+ // Use this for initialization
129
+ void Start () {
130
+
131
+ Destroy(gameObject, lifetime);
132
+
133
+ }
134
+
135
+ // Update is called once per frame
136
+ void Update () {//ノーツの移動(仮)
137
+
138
+ //等速アニメーション
139
+ this.transform.position += new Vector3(0, 0, vector);
140
+ }
141
+ void OnTriggerStay(Collider colobj)//範囲内、右矢印キーを押すとノーツがデリートされる。
142
+ {
143
+ if (Input.GetKeyDown (KeyCode.RightArrow)) {
144
+ Destroy (this.o1);
145
+ }
146
+ }
147
+ }
148
+
149
+ Destroyしているのですがなぜかノーツは消えてくれない状況に陥っています。