Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

How do you set a score limit to end the game?

$
0
0
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; } }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>