- Home /
Displaying score on screen in specific place
I have this script that keeps count of the score when the player collects a collectible, when i try and display the score on screen i get the same 3 errors and cannot figure out how to display the score in a chosen location,
using UnityEngine;
using System.Collections;
public class ScoreGlobal : MonoBehaviour {
public int Score = 0;
void OnGUI()
{
GUILayout.Label(Rect(10,10), "score"+Score);
}
}
how can i display this on screen without errors?
sorry if its unclear.
Answer by aldonaletto · May 19, 2013 at 10:45 PM
You should post the errors you're having, and at which lines! Anyway, there are two errors in line 10: in C# you must use new Rect instead of just Rect; Rect requires 4 parameters (x, y, width, height), not two as you're passing. Line 10 should be something like this:
GUILayout.Label(new Rect(10,10, 200, 30), "score"+Score);
If you have other errors, remember to tell which and where are the errors!
i have used that line and others that are similar but i still get theses errors link text
GUILayout aligns the fields automatically, thus it doesn't require the Rect parameter - remove the first parameter or use GUI.Label ins$$anonymous$$d:
GUILayout.Label("score"+Score);
or
GUI.Label(new Rect(10,10, 200, 30), "score"+Score);