Skip to content

Commit

Permalink
Fixed Playback error & some other cleanups
Browse files Browse the repository at this point in the history
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?)
  • Loading branch information
n-c0de-r committed Feb 3, 2023
1 parent f428ff8 commit 04deadc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion NightLifeDrive/Assets/Prefabs/Traffic cone 1.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 33 additions & 14 deletions NightLifeDrive/Assets/Scripts/BackgroundMusicControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioSource>();
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);
/// <summary>
/// Gets the next song in the list and plays it.
/// </summary>
private void NextSong()
{
songNumber++;
songNumber %= songArray.Length;

trackNumber++;
trackNumber %= songArray.Length;
}
PlaySong(songArray[songNumber]);
}

/// <summary>
/// Plays a given song object.
/// </summary>
/// <param name="song">The Song to play.</param>
private void PlaySong(Song song)
{
audioSource.clip = song.file;
songTitle.text = song.name;
StartCoroutine(animateSong());
audioSource.Play();
}

/// <summary>
Expand All @@ -56,6 +70,11 @@ private void ShufflePlaylist(Song[] songs)
}
}

/// <summary>
/// Shows the currently played title in an info box.
/// Basically just switches Animation triggers.
/// </summary>
/// <returns>A delay time for the display animation.</returns>
IEnumerator animateSong()
{
songAnimation.SetBool("isShowing", true);
Expand Down
2 changes: 1 addition & 1 deletion NightLifeDrive/Assets/Scripts/TileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TileController : MonoBehaviour
[SerializeField]
private SpawnObstacle obstacleSpawner;

private const int DELETE_TIME = 60;
private const int DELETE_TIME = 180;

/// <summary>
/// Spawns an obstacle at certain predefined positions.
Expand Down

0 comments on commit 04deadc

Please sign in to comment.