HI All,
I’m making a maze and I have set a 90 second time limit to finish a level. So now I have a countdown showing on the screen. (1:30, 1:29, 1:28 etc…). I think I want to change this to a score countdown such as 90. 89. 88 etc… The score will start at 90 and will reduce one point per second of play. I’m not sure where to look in order to figure out how to do this. I know how to get the time countdown on the screen, but no clue where to look for getting the score counting down instead. Does anyone have any suggestions or ideas?
Thanks
Mabey you want somthing like this?
var score = 90;
function Update()
{
if(score > 0)
{
ApplyScoreChanges();
}
else
{
//Insert Lose Code Here
}
}
function ApplyScoreChanges()
{
yield WaitForSeconds(1.0);
score = score - 1;
}
You can then attach this to an empty game object and have the score counter display the current score.
Hi Robo,
Thanks for the quick reply! I never thought it would be that simple! Any idea how I get it to show in the OnGUI function?
Probably the exact same way as how you got the time in there?
From the top of my head (as a C# programmer):
function OnGUI(){
GUI.Label(Rect (0, 0, 50, 100),score.ToString());
}
That might not even work. But you know what I mean 
That did work and I had just found another way. But now the “ApplyScoreChanges” is giving me an “unknown indentifier” error. I’ve tried to move the “waitForSeconds” function to the if statement, but that gives me a coroutine error and the 90 doesn’t change. I’m pretty weak with coding (although getting better). Here’s my code:
static var score = 90;
var mySkin : GUISkin;
function Update()
{
if(score > 0)
{
ApplyScoreChages();
}
else
{
Application.Quit();
}
}
function ApplyScoreChanges()
{
yield WaitForSeconds(1.0);
score = score - 1;
}
function OnGUI(){
GUI.skin = mySkin;
text = "Score: "+score;
GUI.Label (Rect(20, 20, 200, 200), text);
}
Any ideas? I know I’m missing something simple.
My version, not tested, hope it helps.
static var score:int = 90;
var mySkin:GUISkin;
function Update()
{
if(score > 0)
{
ApplyScoreChages();
}
else
{
Application.Quit();
}
}
function ApplyScoreChanges()
{
score -= Time.deltaTime;
}
function OnGUI(){
GUI.skin = mySkin;
text = "Score: "+score;
GUI.Label (Rect(20, 20, 200, 200), text);
}
Well I though it was a good even if Unity didn’t. I can get the score to now go from 90-0, but it goes VERY quickly and I can’t figure out how to slow it down. Here’s the code so far.
static var score = 90;
var scoreNew;
var minus = false;
var mySkin : GUISkin;
function Update()
{
if(score > 0)
{
score = score -1;
}
else
{
Application.Quit();
}
}
function OnGUI(){
GUI.skin = mySkin;
text = "Score: "+ score;
GUI.Label (Rect(20, 20, 200, 200), text);
}
The Update() function is called every frame, so if your game runs at 60 frames per second, your game is done in one and a half second 
I’m going to let you figure out yourself how to program it, but what you have to do is make a variable that you set at the same moment you decrease 1 point of score to Time.time + 1. Around the code that decreases your score with 1 and sets that nextDecrease variable to Time.time + 1, you make an if statement that requires the nextDecrease variable to be smaller that Time.time, and if that is the case, score is decreased and the variable set again.
Hooray, you have a timer 
EDIT okay fuck it, here you go:
static var score = 90;
var scoreNew;
var minus = false;
//make a variable that contains the time the next
//score decrease should happen
var nextScoreDecrease : float;
var mySkin : GUISkin;
function Update()
{
//if the score is above 0 and it is time for another decrease...
if(score > 0 nextScoreDecrease <= Time.time)
{
//decrease score by 1
score -= 1; // -= is the same as 'score - 1'
//since we want to decrease the score every second,
//the next decrease will be 1 second from now
nextScoreDecrease = Time.time + 1;
}
else
{
Application.Quit();
}
}
function OnGUI(){
GUI.skin = mySkin;
text = "Score: "+ score;
GUI.Label (Rect(20, 20, 200, 200), text);
}
:lol: TY for the script i also was looking for something like this. 
I spent 3 years in the worst community ever, so what a sweet feeling to now be in the greatest community of givers.
I also like to figure things out for myself, so i was hoping you would of held out for a couple of more post lol 8)
EDIT Iwas having somr errors with that code(idkw) so i altered it a little to get it to work(for me) so here is another version. sorry i took out your comments Adriaan 
static var score = 90;
var scoreText : GUIText;
var nextScoreDecrease : int;
var mySkin : GUISkin;
var minus = false;
function Update() {
if(score > 0 nextScoreDecrease <= Time.time) {
score -= 1;
nextScoreDecrease = Time.time + 1;
}
else {
Application.Quit();
}
}
function OnGUI() {
GUI.skin = mySkin;
GUI.Label (Rect (25, 25, 100, 30), "Score: "+ score);
}
Code Naked 8)
Just decrease it with the delta time value, that way you would decrease it by 1 seconds in realtime.
I think deltaTime is rounded to a bunch of decimals in some way, which would make this technique to be inaccurate on the long term.
Thanks for all of your help. Adrianns worked well for me (and I even studied it so I could learn how it was done
I’ll play with the other ideas too just so I can get a little more comfortable with .js
Well, if that was the case, we wouldn’t use it to make the game frame rate independent. Time.deltaTime is used to deal with time based situations and would work great here.