#pragma strict
var audio1 : AudioClip;
var audio2 : AudioClip;
var audio3 : AudioClip;
var audio4 : AudioClip;
private var Health : HealthManager;
function Start()
{
Health = GameObject.Find("CharacterControl").GetComponent(HealthManager);
}
function Update()
{
if (Health.playerHealth >= 80)
{
GetComponent.<AudioSource>().Stop();
GetComponent.<AudioSource>().clip = audio4;
GetComponent.<AudioSource>().Play();
}
else if (Health.playerHealth >= 60)
{
GetComponent.<AudioSource>().Stop();
GetComponent.<AudioSource>().clip = audio3;
GetComponent.<AudioSource>().Play();
}
else if (Health.playerHealth >= 40)
{
GetComponent.<AudioSource>().Stop();
GetComponent.<AudioSource>().clip = audio2;
GetComponent.<AudioSource>().Play();
}
else if (Health.playerHealth >= 20)
{
GetComponent.<AudioSource>().Stop();
GetComponent.<AudioSource>().clip = audio1;
GetComponent.<AudioSource>().Play();
}
}
I’m calling a few AudioClips to play when the player is damaged, with the variable being the current health after you take damage. How exactly would I stop one sound and start another, because the code I’m using bugs out. I’m not sure if it plays the same clips over each other, or something else, i just know it doesn’t work. Any feedback is appreciated, thanks guys