Hiya, Im very new to Unity so i apologize for the silly questions.
Ive made a game where you go around and collect different objects, and each time you do it adds a point to a counter i made. ( made from several different tutorials)
The Game ends after a set amount of time and goes to a different scene and i wanted to have a final score come up with a Pass or Fail depending on what score you got.
How would i go about making this?
Thank You
You can try to do Something like that:
var score:int;
var leveldone:boolean;
function GotACoin () {
//Call this fuction when you grabed a coin
score+=1;
}
function Update () {
//Make level done true when the level is finished
if(leveldone==true){
if(score>=CoinsRequired){
//Put here the code needed
}
}
}
Try this:
`var score : int = 0; //amount of objetcs picked up
var maxScore : int = 10; //amount of objects picked up required to stop the game (set it as the amount u want)
gameFinished : boolean = false;
function OnPickUp () { //tell me if u also need a script to trigger an action when the object is picked up
score += 1;
}
function Update () {//this function is called every frame…
if(score == maxScore) {//in this case it’ll check for us if the amount of object collected have reached the deadline we’ve set…
EndGame(); //if so it’ll call the function EndGame…
}
}
function OnGUI () {//this function allow us to add GUI or UI to our game to make a lot of stuff like scoreboard, tchat or credit and much more
if(gameFinished == true) {//so if the game is finished then it’ll add some gui and stop the game…
Time.timeScale = 0;
if(GUI.Button(Rect(Screen.width / 2 - Screen.width / 4, Screen.height / 2 + Screen.height / 4,Screen.width / 4, screen.height / 4), “Try again”)) {
Application.ReloadLevel();
}
//add some to leave game etc…
}
}`
Feel free to ask me any question
Hope this help ;D