GUI Text Score counter

In my game, you play with time. the longer you stay in the game, the more points you get.
So if the game starts, your score is 0. It counts from 0 to 7 in 1 second. Now I don’t know what I do wrong, but I can’t fix this problem. Someone who can help me out?

EDIT

This is what I got right now, but I don’t know how to add a GUI Text that counts from 0 to … (no end).

var score: int = 0;
var addscore = 7;
 
function Update() {
       addscore += Time.deltaTime;
}

Please help :smiley:

function OnGUI(){
GUI.Box(Rect(Screen.width/2,Screen.height/2,100,25), score.toString());
}

will make a GUI Box for you with your score in it. However, it doesn’t look like you are ever adding values to your score variable so your score counter may need to be tweaked.

I used InvokeRepeating when i did a timer in my game like this:

function Start(){
InvokeRepeating("EachSecond",1.0,1.0);
}

var score: int = 0;
var addscore = 7;

function EachSecond()
{
score=score+addscore;
}

function OnGUI(){
GUI.Box(Rect(Screen.width*0.5,Screen.height*0.5,100,25), score.ToString());
}

This will draw a GUI label 20 units left, 20 units down, 100W * 30H With the word Score then the actual players score.

GUI.Label (new Rect (20, 20, 100, 30), "Score " + (int)(playerScore));

And I am not sure what this is supposed to do.

var score: int = 0;
var addscore = 7;
 
function Update() {
       addscore += Time.deltaTime;
}

But I would say

var score: int = 0;
var addscore = 7;
 
function Update() {
       score += addscore*Time.deltaTime;
}

EDIT: Here is a code I have actually used. The score increases constantly over time. But Time.deltaTime is small, so I multipy by 100. Then I have OnGUI to show the score as I play.

using UnityEngine;
using System.Collections;

public class ScoreScript : MonoBehaviour {

	float playerScore = 0;


	// Update is called once per frame
	void Update () 
	{
		playerScore += Time.deltaTime;
	}

    //Method to increase score though other scripts:
    //Like collectibles, etc.
	public void IncreaseScore(int amount)
	{
		playerScore += amount;
	}

	void OnDisable()
	{
		//Look to store somewhere else. Like a packet to persist with dont destroy on load.
		PlayerPrefs.SetInt ("Score", (int)(playerScore*100));
	}

	void OnGUI()
	{
		GUI.Label (new Rect (10, 10, 100, 30), "Score " + (int)(playerScore * 100));
	}
}