Advertisement
BeneFager

Untitled

Jan 12th, 2022
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. public class SoundManager : MonoBehaviour
  2. {
  3.     public GameObject soundEffectPrefab;
  4.     public static SoundManager soundManager;
  5.  
  6.     void Awake(){soundManager = this;}
  7.     public static void PlaySound(AudioClip clip, Vector3 pos, Vector2 pitchShift, bool loop)
  8.     {
  9.         GameObject soundEffect = Instantiate(soundManager.soundEffectPrefab, pos, Quaternion.identity);
  10.         AudioSource audioSource = soundEffect.GetComponent<AudioSource>();
  11.         audioSource.clip = clip;
  12.         audioSource.loop = loop;
  13.         audioSource.volume = UltimateVolumeManager.ultimateVolumeManager.soundEffectsfloat;
  14.         SoundEffectBehavior soundScript = soundEffect.GetComponent<SoundEffectBehavior>();
  15.         soundScript.pitchShift = pitchShift;
  16.         audioSource.Play();
  17.     }
  18.     public static void PlaySound(AudioClip clip, Vector3 pos, Vector2 pitchShift){PlaySound(clip, pos, pitchShift, false);}
  19.     public static void PlaySound(AudioClip clip, Vector3 pos){PlaySound(clip, pos, Vector2.zero, false);}
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement