前提・実現したいこと
unityで音ゲーを作っているのですが、譜面に合わせてボタンを押したときに良、可といった判定が出来るように、判定線の近くにボックスコライダーを設置しました。
ですが、指定のボックスコライダがオンになっている時のif文をどう書けばいいかわかりません。
教えてください。
void OnTriggerStay(Collider colobj)
この中だとすべてのボックスコライダに適用されてしまうので…
それか他に良い判定の作り方があれば教えていただければと思います。
中傷はきついっす。
【補足】
現在はMIDIファイルを使って音ゲーを制作しています。
ノーツが流れるレーンは一つです。
SmfLiteというソースを参考にして、スクリプトを作りました。
譜面スクリプト
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SmfLite;
public class Tester : MonoBehaviour
{
// Source MIDI file asset.
public TextAsset sourceFile;
// Test settings. public float bpm; public GameObject o36; public GameObject o37; public GameObject o38; public GameObject o39; public GameObject o40; // MIDI objects. MidiFileContainer song; MidiTrackSequencer sequencer; // Start function (MonoBehaviour). IEnumerator Start () { // Load the MIDI song. song = MidiFileLoader.Load (sourceFile.bytes); var tempo = 120f; // テンポはすでに読み込み済みとする // Wait for one second to avoid stuttering. yield return new WaitForSeconds (1.0f); // Start sequencing. ResetAndPlay (0); } // Reset and start sequecing. void ResetAndPlay (float startTime) { // Play the audio clip.
// audio.Play ();
// audio.time = startTime;
// Start the sequencer and dispatch events at the beginning of the track. sequencer = new MidiTrackSequencer (song.tracks [1], song.division, bpm); DispatchEvents (sequencer.Start (startTime)); } // Update function (MonoBehaviour). void Update () { if (sequencer != null && sequencer.Playing) { // Update the sequencer and dispatch incoming events. DispatchEvents (sequencer.Advance (Time.deltaTime)); } } // Dispatch incoming MIDI events. void DispatchEvents (List<MidiEvent> events) { if (events != null) { foreach (var e in events) { if ((e.status & 0xf0) == 0x90) { Debug.Log (e.data1); if (e.data1 == 44) { Instantiate (o36); //イントロ //ノーツをずらす方法 } if (e.data1 == 43) { Instantiate (o37); //イントロ } if (e.data1 == 41) { Instantiate (o38); //イントロ } if (e.data1 == 24) { Instantiate (o40); //jamp } if (e.data1 == 48) { Instantiate (o39); } //仮の譜面 } } } }
}
ノーツスクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Notes : MonoBehaviour {
public float lifetime; public GameObject o1; public float vector; // Use this for initialization void Start () { Destroy(gameObject, lifetime); } // Update is called once per frame void Update () {//ノーツの移動(仮) //等速アニメーション this.transform.position += new Vector3(0, 0, vector); } void OnTriggerStay(Collider colobj)//範囲内、右矢印キーを押すとノーツがデリートされる。 { if (Input.GetKeyDown (KeyCode.RightArrow)) { Destroy (this.o1); } }
}
Destroyしているのですがなぜかノーツは消えてくれない状況に陥っています。
回答2件
あなたの回答
tips
プレビュー