heres my core i have it set on an empty object called game over with a voice saying “game over” attached to my audio source
public class gameOver : MonoBehaviour {
public GUISkin theskin;
Transform theBall;
void Start(){
theBall = GameObject.FindGameObjectWithTag ("ball").transform;
}
void Update(){
if (ScoreKeeper.Score == 10) {
audio.Play ();
}
else if (ScoreKeeper.Score2 == 10) {
audio.Play();}
}
void OnGUI(){
GUI.skin = theskin;
if (ScoreKeeper.Score==10){
GUI.Label(new Rect(Screen.width/2-350,Screen.height/2-140,2000,1000),"PLAYER 1 WINS!!");
theBall.gameObject.SendMessage("hasWon",null,SendMessageOptions.RequireReceiver);
if(GUI.Button(new Rect(Screen.width/2-100,Screen.height/2-50,200,75),"REMATCH")){
ScoreKeeper.Score=0;
ScoreKeeper.Score2=0;
theBall.gameObject.SendMessage("resetBall",.05f,SendMessageOptions.RequireReceiver);
}
if(GUI.Button(new Rect(Screen.width/2-100,Screen.height/2+50,200,75),"QUIT")){
ScoreKeeper.Score=0;
ScoreKeeper.Score2=0;
theBall.gameObject.SendMessage("resetBall",.05f,SendMessageOptions.RequireReceiver);
Application.LoadLevel(0);
}
}
else if(ScoreKeeper.Score2==10){
GUI.Label(new Rect(Screen.width/2-02.6f,Screen.height/2-140,2000,1000),"PLAYER 2 WINS!!");
theBall.gameObject.SendMessage("hasWon",null,SendMessageOptions.RequireReceiver);
if(GUI.Button(new Rect(Screen.width/2-100,Screen.height/2-50,200,75),"REMATCH")){
ScoreKeeper.Score=0;
ScoreKeeper.Score2=0;
theBall.gameObject.SendMessage("resetBall",.05f,SendMessageOptions.RequireReceiver);
}
if(GUI.Button(new Rect(Screen.width/2-100,Screen.height/2+50,200,75),"QUIT")){
ScoreKeeper.Score=0;
ScoreKeeper.Score2=0;
theBall.gameObject.SendMessage("resetBall",.05f,SendMessageOptions.RequireReceiver);
Application.LoadLevel(0);
}
}
}
}
the problem is that the game over sound doesnt play unitl i press the rematch button instead of when the score equals 10 can you let me know whats wrong please?