Setup and play area prefab

This commit is contained in:
Max 2025-03-19 09:23:22 +01:00
parent fe61df43e7
commit af12b601fc
166 changed files with 14014 additions and 10 deletions

View file

@ -0,0 +1,52 @@
using System;
using DefaultNamespace;
using UnityEngine.Audio;
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public Sound[] sounds;
public SoundGroup[] soundGroups;
private void Awake()
{
foreach (SoundGroup group in soundGroups)
{
foreach (Sound s in group.sounds)
{
InnitializeSound(s);
}
}
foreach (Sound s in sounds)
{
InnitializeSound(s);
}
}
public void Play(string name)
{
SoundGroup sg = Array.Find(soundGroups, group => group.name == name);
if (sg != null)
{
sg.Play();
return;
}
Sound s = Array.Find(sounds, sound => sound.name == name);
if (s == null)
{
Debug.LogWarning($"Sound: {name} not found!");
return;
}
s.source.Play();
}
private void InnitializeSound(Sound s)
{
s.source = gameObject.AddComponent<AudioSource>();
s.source.clip = s.clip;
s.source.volume = s.volume;
s.source.pitch = s.pitch;
}
}