Advertisement
CakeMeister

Soundmanager phan 16

Jul 13th, 2017
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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 AudioClip coins, swords, destroy;
  8.  
  9.     public AudioSource adisrc;
  10.     // Use this for initialization
  11.     void Start () {
  12.         coins = Resources.Load<AudioClip>("Game coin");
  13.         swords = Resources.Load<AudioClip>("Sword");
  14.         destroy = Resources.Load<AudioClip>("Rock Crash");
  15.         adisrc = GetComponent<AudioSource>();
  16.  
  17.     }
  18.  
  19.     public void Playsound(string clip)
  20.     {
  21.         switch (clip)
  22.         {
  23.             case "coins":
  24.                 adisrc.clip = coins;
  25.                 adisrc.PlayOneShot(coins, 0.6f);
  26.                 break;
  27.  
  28.             case "destroy":
  29.                 adisrc.clip = destroy;
  30.                 adisrc.PlayOneShot(destroy, 1f);
  31.                 break;
  32.  
  33.             case "sword":
  34.                 adisrc.clip = swords;
  35.                 adisrc.PlayOneShot(swords, 1f);
  36.                 break;
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement