- Home /
How Would I Make The Game Go To Next Level After i Hit 1000 Points?
Hey Guys :)
I'm Currently Working on a FPS/Gothic/Zombie Game and its really turning out great! I Would Like To Implement Some Sort Of Script When i reach 1000 Points On The Score Manager it will Show a screen saying Level Completed and give me the option to go to next level (scene). I'm Using The FPSKitV1.2 There score manager is what I'm using ATM. if that's any help.
You should be able to piece this together if you just look around. Points are points, doesn't matter what the game is about ; screen with text on it and somethin to allow you the option of going to the next level sounds like GUI to me ; and changing levels is changing levels whether you're going up one, down 5, or restarting the one you're already in. All those topics have multiple posts in here.
Answer by aldonaletto · May 22, 2012 at 11:58 AM
FPSKit is a great tool to help Unity users - but it's not an official Unity tool, thus most UA posters don't know it in depth (me included).
But maybe you can adapt the basic idea to your game: try to locate the script where the points are accumulated (ScoreManager?). Supposing you've found the script, and there's a variable called score that holds the current score, you should add the necessary code to it - something like this:
// declare this variable outside any function: var showDialog: boolean = false;
// add this line to Update: function Update(){ if (score > 1000) showDialog = true; ... (remaining Update code, if any) }
// create function OnGUI (or modify it, if already existing): function OnGUI(){ if (showDialog){ var next = Application.loadedLevel + 1; // calculate next level index if (next < Application.levelCount){ // if there exists a next level... if (GUI.Button(Rect(200,100,300,50),"Load next level")){ // show the button Application.LoadLevel(next); // and load it if button pressed } } } ... (remaining OnGUI code, if any) }
EDITED: Since you've posted the ScoreManager script, things became a lot easier: you don't need the variable showDialog neither the Update modification - all you need is to modify the OnGUI function as follows:
... function OnGUI(){ GUI.skin = mySkin; var style1 = mySkin.customStyles[0];
// JUST ADD THIS CODE: if (currentScore > 1000){ var next = Application.loadedLevel + 1; // calculate next level index if (next < Application.levelCount){ // if there exists a next level... if (GUI.Button(Rect(300, Screen.height - 110,280,60),"Load next level")){ // show the button Application.LoadLevel(next); // and load it if button pressed } } } // ***
GUI.Label (Rect(40, Screen.height - 80,100,60)," SCORE :"); GUI.Label (Rect(100, Screen.height - 80,160,60),"" + currentScore, style1); ...
Wow, $$anonymous$$ate... Thank you so much!! Unfortunately i keep getting a error when implementing this saying.
assets/resources/Newscripts/Scoremanager.js(3,20): UCE0001 ';' expected. Insert a semicolon at the end.
Thing is it has one and im a little confused.
Would it be easier if i linked the script? @script ExecuteInEdit$$anonymous$$ode()
var currentScore : int = 0;
var time : float = 0.0;
var hitCrosshairTexture : Texture;
private var alphaHit : float;
var hitSound : AudioClip;
var mySkin : GUISkin;
var pointsToNextRank : int = 50;
var rank : int = 0;
var rankSound : AudioClip;
function Update () {
if (time > 0){
time -= Time.deltaTime;
}
alphaHit = time;
}
function DrawCrosshair(){ yield WaitForSeconds(0.1); time = 1.0; audio.PlayOneShot(hitSound, .5); }
function addScore(value : int){ yield WaitForSeconds(0.2); currentScore += value;
if(currentScore >= pointsToNextRank){
rank++;
PlayAudioClip(rankSound, transform.position, 1.0);
pointsToNextRank += currentScore;
}
}
function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) { var go = new GameObject ("One shot audio"); go.transform.position = position; var source : AudioSource = go.AddComponent (AudioSource); source.clip = clip; source.volume = volume; source.pitch = Random.Range(0.95,1.05); source.Play (); Destroy (go, clip.length); return source; }
function OnGUI(){ GUI.skin = mySkin; var style1 = mySkin.customStyles[0];
GUI.Label (Rect(40, Screen.height - 80,100,60)," SCORE :");
GUI.Label (Rect(100, Screen.height - 80,160,60),"" + currentScore, style1);
GUI.Label (Rect(40, Screen.height - 110,100,60)," LVL :");
GUI.Label (Rect(100, Screen.height - 110,160,60),"" + rank, style1);
GUI.color = Color(1.0, 1.0, 1.0, alphaHit);
GUI.DrawTexture (Rect ((Screen.width - hitCrosshairTexture.width)/2, (Screen.height - hitCrosshairTexture.height)/2, hitCrosshairTexture.width, hitCrosshairTexture.height), hitCrosshairTexture);
}
(I had to remove the stuff i added cos it was currupting my game. But if you know why that script you showed me wasnt working would be appreciated.
Sorry if i did that wrong. New to UA, :)
var boolean showDialog = false;
^^ is The only line im getting a error on now. It says that i need to add a semicolon at the end.
$$anonymous$$y bad! That's what we get when writing in two languages - this declaration was a mix of JS and C#, which none of them would understand. It should be:
var showDialog: boolean = false;
Answer fixed!
Yeah that fixed that. Now i have another error... if (score > 1000) showDialog = true;
Unity cant recognise "Score"
@AusAndrew, since you've posted the whole script, I will suggest a more specific alteration - only the OnGUI must have some code added. Take a look at the question - I edited it to add the necessary code.
Answer by venkspower · May 23, 2012 at 04:51 AM
var score : int;
var a : int = 0;
scoreText : GUIText;
function Start(){
score = 0;
}
function OnGUI(){
scoreText.text = ""+score;
}
function Update(){
score++;
if(score > 1000){
a = 1;
}
if(a == 1){
Application.LoadLevel("LevelName");
}
}
Answer by AusAndrew19 · May 23, 2012 at 07:24 AM
None of this is working... Keep getting so many errors. Guess this is too advanced for my noob skills. if anyone thinks they can help add me on msn, AusAndrew@hotmail.com thanks :)
Your answer
Follow this Question
Related Questions
new to scripting need some fps controll help plz :) 2 Answers
fps change graphic 1 Answer
a strange problem ? 1 Answer
Simple Fps Prefab 1 Answer
Weapon switching using array 1 Answer