From 04deadc85141ea3cc4cc7d67c3944a5e533971be Mon Sep 17 00:00:00 2001 From: n-c0de-r <78597469+n-c0de-r@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:11:48 +0100 Subject: [PATCH] Fixed Playback error & some other cleanups Upped the time for track removal a bit, removed strange shapes in explosion animation, renamed and restructured some stuff in music playback to solve the problem and make it even more modular for further extension (Maybe next time use event driven design here?) --- .../Assets/Prefabs/Traffic cone 1.prefab | 2 +- .../Assets/Scripts/BackgroundMusicControl.cs | 47 +++++++++++++------ .../Assets/Scripts/TileController.cs | 2 +- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/NightLifeDrive/Assets/Prefabs/Traffic cone 1.prefab b/NightLifeDrive/Assets/Prefabs/Traffic cone 1.prefab index 3325a31..7c74de5 100644 --- a/NightLifeDrive/Assets/Prefabs/Traffic cone 1.prefab +++ b/NightLifeDrive/Assets/Prefabs/Traffic cone 1.prefab @@ -5241,7 +5241,7 @@ ParticleSystemRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: 9613221d48fcce6418786f0b2763d31e, type: 2} + - {fileID: 2100000, guid: f629c6e43dba4bf38cb74d8860150664, type: 2} - {fileID: 2100000, guid: 9ee57d79f386aee4281fe4f955fd774d, type: 2} m_StaticBatchInfo: firstSubMesh: 0 diff --git a/NightLifeDrive/Assets/Scripts/BackgroundMusicControl.cs b/NightLifeDrive/Assets/Scripts/BackgroundMusicControl.cs index 5e55355..f00617e 100644 --- a/NightLifeDrive/Assets/Scripts/BackgroundMusicControl.cs +++ b/NightLifeDrive/Assets/Scripts/BackgroundMusicControl.cs @@ -5,36 +5,50 @@ [RequireComponent(typeof(AudioSource))] public class BackgroundMusicControl : MonoBehaviour { + [SerializeField] private Song[] songArray; + [SerializeField] private TMP_Text songTitle; [SerializeField] private Animator songAnimation; [SerializeField] private int displayDelay = 3; private AudioSource audioSource; - private int trackNumber = 0; - - [SerializeField] private Song[] songArray; + private int songNumber = 0; // Start is called before the first frame update void Start() { audioSource = GetComponent(); ShufflePlaylist(songArray); - StartCoroutine(loopMusic(audioSource)); + PlaySong(songArray[songNumber]); } - private IEnumerator loopMusic(AudioSource audio) { - while (true) { - audio.clip = songArray[trackNumber].file; - songTitle.text = songArray[trackNumber].name; - StartCoroutine(animateSong()); - audio.Play(); + void Update() + { + if (!audioSource.isPlaying) NextSong(); + } - yield return new WaitForSeconds(audio.clip.length); + /// + /// Gets the next song in the list and plays it. + /// + private void NextSong() + { + songNumber++; + songNumber %= songArray.Length; - trackNumber++; - trackNumber %= songArray.Length; - } + PlaySong(songArray[songNumber]); + } + + /// + /// Plays a given song object. + /// + /// The Song to play. + private void PlaySong(Song song) + { + audioSource.clip = song.file; + songTitle.text = song.name; + StartCoroutine(animateSong()); + audioSource.Play(); } /// @@ -56,6 +70,11 @@ private void ShufflePlaylist(Song[] songs) } } + /// + /// Shows the currently played title in an info box. + /// Basically just switches Animation triggers. + /// + /// A delay time for the display animation. IEnumerator animateSong() { songAnimation.SetBool("isShowing", true); diff --git a/NightLifeDrive/Assets/Scripts/TileController.cs b/NightLifeDrive/Assets/Scripts/TileController.cs index 3b08262..892df7c 100644 --- a/NightLifeDrive/Assets/Scripts/TileController.cs +++ b/NightLifeDrive/Assets/Scripts/TileController.cs @@ -8,7 +8,7 @@ public class TileController : MonoBehaviour [SerializeField] private SpawnObstacle obstacleSpawner; - private const int DELETE_TIME = 60; + private const int DELETE_TIME = 180; /// /// Spawns an obstacle at certain predefined positions.