- Home /
Change scene upon reaching certain score value
I'm trying to run a Pong game where, upon one of the players reaching 10 points, the scene will change to a game over screen that is specific to the player. I've tried this: void winRight() { if (leftScore == 10) { Application.LoadLevel("P1Win"); } }
void winLeft()
{
if (rightScore == 10)
{
Application.LoadLevel("GameOver");
}
}
But once a player reaches 10 points, nothing happens. Any advice?
Answer by sohail11330 · Nov 22, 2016 at 08:27 PM
As the score updating one by one ,so you have to put this condition into Update () like this
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public int rightScore;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (rightScore == 10)
{
Application .LoadLevel ("GameOver");
}
}
}
`
Your answer
![](https://koobas.hobune.stream/wayback/20220612101155im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
When die - reset score from the last scene 2 Answers
DontDestroyOnLoad duplicate prevention code is deleting the original player 2 Answers
Unity - dragging a RigidBody2D Gameobject by mouse/touch without any lag 0 Answers
(2D) Can't make a scene transition between 2 game objects colliding - 2019 1 Answer
How do you fix a sprite to a camera that follows another sprite, but still be able to move it? 0 Answers