31 lines
796 B
C#
31 lines
796 B
C#
using UnityEngine;
|
|
|
|
// Written by Lilia Schwab
|
|
public class SFXManager : MonoBehaviour
|
|
{
|
|
public static SFXManager instance;
|
|
|
|
[SerializeField] private AudioSource sFXObject;
|
|
|
|
private void Awake() {
|
|
if (instance == null) {
|
|
instance = this;
|
|
}
|
|
}
|
|
|
|
// Muss noch schauen, wie ich das für das jeweilige Vieh seine seperaten Sounds einstelle und nicht universal
|
|
public void PlaySFXClip(AudioClip clip, Transform spawnTransform, float volume) {
|
|
AudioSource audioSource = Instantiate(sFXObject, spawnTransform.position, Quaternion.identity);
|
|
|
|
audioSource.clip = clip;
|
|
|
|
audioSource.volume = volume;
|
|
|
|
audioSource.Play();
|
|
|
|
float clipLength = audioSource.clip.length;
|
|
|
|
Destroy(audioSource, clipLength);
|
|
}
|
|
}
|