Bugs 1
This commit is contained in:
67
Assets/Scripts/AudioManager.cs
Normal file
67
Assets/Scripts/AudioManager.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public List<SoundEffect> soundEffects = new List<SoundEffect>();
|
||||
|
||||
public static AudioManager Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
var soundEffect = new SoundEffect(child.name, child.GetComponent<AudioSource>());
|
||||
if (soundEffect != null)
|
||||
{
|
||||
soundEffects.Add(soundEffect);
|
||||
}
|
||||
}
|
||||
|
||||
print(soundEffects);
|
||||
}
|
||||
|
||||
public void PlaySound(string soundName)
|
||||
{
|
||||
if (soundName == "Punch")
|
||||
{
|
||||
soundEffects.Find(x => x.name == "Punch").audioSource.Play();
|
||||
soundEffects.Find(x => x.name == "Punch 2").audioSource.Play();
|
||||
soundEffects.Find(x => x.name == "Punch 3").audioSource.Play();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var soundEffect in soundEffects)
|
||||
{
|
||||
if (soundEffect.name == soundName)
|
||||
{
|
||||
soundEffect.audioSource.Play();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.LogWarning($"Sound '{soundName}' not found!");
|
||||
}
|
||||
}
|
||||
|
||||
public class SoundEffect
|
||||
{
|
||||
public string name;
|
||||
public AudioSource audioSource;
|
||||
|
||||
public SoundEffect(string name, AudioSource audioSource)
|
||||
{
|
||||
this.name = name;
|
||||
this.audioSource = audioSource;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AudioManager.cs.meta
Normal file
2
Assets/Scripts/AudioManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab3338b5eb5fc46caac119dfaba50ae3
|
||||
15
Assets/Scripts/ObstacleCourse.cs
Normal file
15
Assets/Scripts/ObstacleCourse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ObstacleCourse : MonoBehaviour
|
||||
{
|
||||
public static GameObject playerWon;
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
playerWon = collision.gameObject;
|
||||
GameManager.Instance.GameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/ObstacleCourse.cs.meta
Normal file
2
Assets/Scripts/ObstacleCourse.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 746e2bd0f68be467eb1b2b19c7c513af
|
||||
Reference in New Issue
Block a user