Advertisement
evelynshilosky

SoundManager - Part 31

Feb 1st, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SoundManager : MonoBehaviour
  6. {    
  7.     public static SoundManager Instance { get; set; }
  8.  
  9.     // Sound FX
  10.     public AudioSource dropItemSound;
  11.     public AudioSource craftingSound;
  12.     public AudioSource toolSwingSound;
  13.     public AudioSource chopSound;
  14.     public AudioSource pickupItemSound;
  15.     public AudioSource grassWalkSound;
  16.     public AudioSource treeChopSound;
  17.  
  18.     //Music
  19.     public AudioSource startingZoneBGMusic;
  20.     public AudioSource natureBGMusic;
  21.     public AudioSource birdBG;
  22.     public AudioSource bird1BG;
  23.     public AudioSource bird2BG;
  24.     public AudioSource bushesBG;
  25.     public AudioSource leavesBG;
  26.  
  27.     public AudioSource voiceovers;
  28.  
  29.     private void Awake()
  30.     {
  31.         if (Instance != null && Instance != this)
  32.         {
  33.  
  34.             Destroy(gameObject);
  35.  
  36.         }
  37.         else
  38.         {
  39.             Instance = this;
  40.         }
  41.     }
  42.  
  43.     public void PlaySound(AudioSource soundToPlay)
  44.     {
  45.         if (!soundToPlay.isPlaying)
  46.         {
  47.             soundToPlay.Play();
  48.         }
  49.     }
  50.  
  51.     public void PlayVoiceOvers(AudioClip clip)
  52.     {
  53.         voiceovers.clip = clip;
  54.         if (!voiceovers.isPlaying)
  55.         {
  56.             voiceovers.Play();
  57.         }
  58.         else
  59.         {
  60.             voiceovers.Stop();
  61.             voiceovers.Play();
  62.         }
  63.     }
  64.  
  65.     public void StopVoiceOvers(AudioClip clip)
  66.     {
  67.         voiceovers.clip = clip;
  68.         voiceovers.Stop();
  69.     }
  70.  
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement