using System.Collections; using UnityEngine; public class SoundGameController : MonoBehaviour { SoundTrackManager soundTrackManager = new(); GameObject notePrefabSwipe, notePrefabTap; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { TextAsset soundTrackJson = Resources.Load("WalkDogs/SoundTrack/track_1"); if (soundTrackJson != null) { string soundTrackString = soundTrackJson.text; soundTrackManager.ImportFromJson(soundTrackString); } notePrefabSwipe = Resources.Load("WalkDogs/Note/NoteSwipe"); notePrefabTap = Resources.Load("WalkDogs/Note/NoteTap"); StartCoroutine(PlaySoundGame()); } // Update is called once per frame void Update() { } IEnumerator PlaySoundGame() { float startTime = Time.time; float endTime = startTime + soundTrackManager.length; while (Time.time < endTime) { foreach (var note in soundTrackManager.soundAction) { if (!note.isActive && Time.time >= startTime - GameData.noteStartLeadTime) { note.isActive = true; CreateNote(note.time, note.action); continue; } } } return null; } private void CreateNote(float hitTime, string action) { GameObject note; if (action == "tap") { note = Instantiate(notePrefabTap); } else { note = Instantiate(notePrefabSwipe); } NoteController noteController = note.GetComponent(); noteController.speed = soundTrackManager.speed; noteController.hitTime = hitTime; noteController.action = action; } }