Question by
henriksen.shane · Dec 20, 2015 at 03:19 PM ·
audio
Audio wont Play when in an if statement
So i have an AudioSource attached to UI button that I want to play when conditions are met for an If statement. I know the If statement is being executed due to a debug line I have in the block, but the audio won't play. Furthermore, when I move the audio call outside the if statement it does play. Why?
public void Clicked (){
GameObject manage = GameObject.Find ("GameManagerObject");
GameManager gameScript = manage.GetComponent<GameManager> ();
if (gameScript.allowActions == true) {
if ((gameScript.playerOneTurn) && (gameObject.tag.Contains("Play1"))){
if (gameScript.blueManaOne < 3){
gameScript.actionText.text = "Get more blue energy!";
}
else{
gameScript.blueManaOne = gameScript.blueManaOne - 3;
gameScript.blueOne.value = (float)gameScript.blueManaOne;
gameScript.blueManaOneText.text = "" + gameScript.blueManaOne;
Debug.Log ("audio should play here");
GetComponent<AudioSource>().Play();
gameScript.damageHolder = gameScript.damageHolder + 5;
gameScript.CheckForMatchesAfterReplace();
}
}
else if ((gameScript.playerTwoTurn) && (gameObject.tag.Contains("Play2"))){
if (gameScript.blueManaTwo < 3){
gameScript.actionText.text = "Get more blue energy!";
}
else{
gameScript.blueManaTwo = gameScript.blueManaTwo - 3;
gameScript.blueTwo.value = (float)gameScript.blueManaTwo;
gameScript.blueManaTwoText.text = "" + gameScript.blueManaTwo;
GetComponent<AudioSource>().Play();
gameScript.damageHolder = gameScript.damageHolder + 5;
gameScript.CheckForMatchesAfterReplace();
}
}
}
}
When I move the audio call to just before the second if statement, it works.
Comment
I forgot to mention, this script is attached to the UI button.