- Home /
Score display error
I have a scoring system to give points over time, and to display it, but it doesn't work. Whats wrong here?
var score = 0;
function Start () {
InvokeRepeating("Plus", 0, 0.1);
}
function Plus () {
score += 1;
}
var w = 0.3; // proportional width (0..1)
var h = 0.2; // proportional height (0..1)
private var rect: Rect;
rect.x = (Screen.width*(1-w))/2;
rect.y = (Screen.height*(1-h))/2;
rect.width = Screen.width*w;
rect.height = Screen.height*h;
GUI.Label(rect, score);
Did you mess up when you posted your code in here, or is this how your script actually looks?
Answer by mattyman174 · Mar 01, 2014 at 10:58 PM
All GUI.() code must go in the OnGUI() Function.
so i tried reformatting it, now it looks like this
var score = 0;
function Start () {
InvokeRepeating("Plus", 0, 0.1);
}
function Plus () {
score += 1;
}
function OnGUI (){
//Gui S$$anonymous$$in
GUI.color = Color.red;
GUI.contentColor = Color.red;
GUI.Box(Rect(50, Screen.height -60, 120, 20), GUIContent (score));
GUI.Label(Rect(50, Screen.height -60, 100, 20), GUIContent (" Health" ));
}
it comes up with this error Assets/Scripts/scoreadd.js(17,75): BCE0024: The type 'UnityEngine.GUIContent' does not have a visible constructor that matches the argument list '(int)'.
Just put you variables in there without GUIContent
GUI.Box(Rect(50, Screen.height -60, 120, 20), score);
GUI.Label(Rect(50, Screen.height -60, 100, 20), " Health");
Your answer
Follow this Question
Related Questions
Accessing Script From Other Script Causes Lag? 1 Answer
How would I make the text bigger on this script? 1 Answer
Multiplayer ScoreBoard not Updating Correctly 0 Answers
Unity Game Score Script 1 Answer
How to "Increase score with Y axis"? 1 Answer