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.().AddForce(10,0,0);
}
function Update ()
{
var cvel = GetComponent.().velocity;
var tvel = cvel.normalized * cSpeed;
GetComponent.().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;
}
}
↧