Skip to content
Permalink
d864e80fc3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
93 lines (80 sloc) 2.79 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManagerScript : MonoBehaviour
{
public static AudioClip Collectsound, Jumpsound, Swordsound, Diesound, Throwsound, Hurtsound, Heartsound, GhsotHurtSound, Keysound, teleportSound, evilLaughSound, BeeHitSound;
static AudioSource audioSrc;
public AudioClip otherClip;
// Start is called before the first frame update
void Start()
{
//set up references to sound effects
Swordsound = Resources.Load<AudioClip>("Sword");
Jumpsound = Resources.Load<AudioClip>("Jump");
Collectsound = Resources.Load<AudioClip>("Collecting");
Diesound = Resources.Load<AudioClip>("Laugh");
Throwsound = Resources.Load<AudioClip>("Throw");
Hurtsound = Resources.Load<AudioClip>("Hurt");
Heartsound = Resources.Load<AudioClip>("Heart");
GhsotHurtSound = Resources.Load<AudioClip>("GhostHurt");
Keysound = Resources.Load<AudioClip>("Key");
teleportSound = Resources.Load<AudioClip>("teleport");
evilLaughSound = Resources.Load<AudioClip>("Evil Laugh");
BeeHitSound = Resources.Load<AudioClip>("BeeHit");
audioSrc = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
}
//Switch cases depending on the sound that is to be played, chooses that clip
public static void PlaySound(string clip)
{
switch (clip)
{
case "Sword":
audioSrc.PlayOneShot(Swordsound);
break;
case "Jump":
audioSrc.PlayOneShot(Jumpsound);
break;
case "Laugh":
audioSrc.PlayOneShot(Diesound);
break;
case "Collecting":
audioSrc.PlayOneShot(Collectsound);
break;
case "Throw":
audioSrc.PlayOneShot(Throwsound);
break;
case "Hurt":
audioSrc.PlayOneShot(Hurtsound);
break;
case "Heart":
audioSrc.PlayOneShot(Heartsound);
break;
case "GhostHurt":
audioSrc.PlayOneShot(GhsotHurtSound);
break;
case "Key":
audioSrc.PlayOneShot(Keysound);
break;
case "teleport":
audioSrc.PlayOneShot(teleportSound);
break;
case "BeeHit":
audioSrc.PlayOneShot(BeeHitSound);
break;
}
}
//outside music begin
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
audioSrc.clip = otherClip;
audioSrc.Play();
}
}
}