How do you set a score limit to end the game?
Im working on a Pong remake and after one of the players score 5 points I want the game to show who won (i.e player 1 wins or player 2 wins) then stops the game and returns to the main menu. How do I set a score limit to end the game? Right now the game goes on forever, I have everything working except my main menu( still trying to figure out the scene manager) and the score limit to stop gameplay. Thanks in advance! Here's what I have so far attached to the ball.
pragma strict
import UnityEngine.UI;
var cSpeed:float = 10.0;
var sFactor:float = 10.0;
var speed:float = 5.0;
static var playerScore:int = 0;
static var enemyScore:int = 0;
function Start ()
{
GetComponent.<Rigidbody>().AddForce(10,0,0);
}
function Update ()
{
var cvel = GetComponent.<Rigidbody>().velocity;
var tvel = cvel.normalized * cSpeed;
GetComponent.<Rigidbody>().velocity = Vector3.Lerp(cvel,tvel,Time.deltaTime * sFactor);
if (transform.position.x > 23)
{
playerScore++;
transform.position.x = 0;
transform.position.y = 0;
}
if (transform.position.x < -23)
{
enemyScore++;
transform.position.x = 0;
transform.position.y = 0;
}
}
Your answer
Follow this Question
Related Questions
Hi,so i'm new to unity and I need help on delaying an object 1 Answer
How to make OnTriggerEnter() change the speed of the Enemy Paddle of a Pong game? 0 Answers
How can I change my player control method to use a touch screen ?? Pong-clone 2D 0 Answers
Variables not showing up in Inspector (JavaScript) 2 Answers