Question by
JamieJamJams · Nov 18, 2015 at 06:30 AM ·
arrayaudiosoundplaysound effects
How can I get my sound array working here?
Here is my code.
I'm trying to figure out why my PlaySound(#); functions work when they are in the "Pick Up" compare tag IF statement, but they don't work when the PlaySound(#); function is placed in the "Finish" IF statement.
I tested the sound files and its not the file.
Any ideas? Thank you. I'm somewhat a beginner, so please offer a more elaborate answer if you can. Thank you.
public void OnTriggerEnter2D (Collider2D other) {
// Picks up gameObjects which are tagged with "Pick Up" and adds one to the player's score.
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
Debug.Log("YOU GOT A STICKER");
PlaySound (0);
score = score + 1;
setScoreText();
}
//Reduce health points if enemy is hit and game over if it hits 0 health points
if (other.gameObject.CompareTag ("Enemy"))
{
Debug.Log ("Enemy hit");
PlaySound (1);
score = score - 1;
if(score <= 0)
{
score = 0;
}
other.gameObject.SetActive (false);
setScoreText();
}
if(other.gameObject.CompareTag ("Finish"))
{
Debug.Log("FinishLine");
if(score >=5)
{
PlaySound(3);
Debug.Log("score is 5 or above");
}
else if(score >=2 && score < 5)
{
PlaySound(4);
Debug.Log("score is below 5");
}
}
void PlaySound(int clip) { AudioSource audio = GetComponent(); audio.clip = audioClip[clip]; audio.Play (); }
Comment