Advertisement
evelynshilosky

SoundManager - Part 39

Apr 18th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 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.     //Music
  18.     public AudioSource startingZoneBGMusic;
  19.     public AudioSource natureBGMusic;
  20.     public AudioSource birdBG;
  21.     public AudioSource bird1BG;
  22.     public AudioSource bird2BG;
  23.     public AudioSource bushesBG;
  24.     public AudioSource leavesBG;
  25.  
  26.     public AudioSource voiceovers;
  27.  
  28.     public AudioSource wateringChannel;
  29.     public AudioClip wateringCan;
  30.  
  31.     private void Awake()
  32.     {
  33.         if (Instance != null && Instance != this)
  34.         {
  35.  
  36.             Destroy(gameObject);
  37.  
  38.         }
  39.         else
  40.         {
  41.             Instance = this;
  42.         }
  43.     }
  44.  
  45.     public void PlaySound(AudioSource soundToPlay)
  46.     {
  47.         if (!soundToPlay.isPlaying)
  48.         {
  49.             soundToPlay.Play();
  50.         }
  51.     }
  52.  
  53.     public void PlayVoiceOvers(AudioClip clip)
  54.     {
  55.         voiceovers.clip = clip;
  56.         if (!voiceovers.isPlaying)
  57.         {
  58.             voiceovers.Play();
  59.         }
  60.         else
  61.         {
  62.             voiceovers.Stop();
  63.             voiceovers.Play();
  64.         }
  65.     }
  66.  
  67.     public void StopVoiceOvers(AudioClip clip)
  68.     {
  69.         voiceovers.clip = clip;
  70.         voiceovers.Stop();
  71.     }
  72.  
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement