Scoring System Java

Hey guys,

I’m currently working on a game and I’m working on implementing a scoring system in my game and it’s not appearing properly. I’ve attached a picture to show what’s happening and where the score is showing up and where I would like the score to actually be. The score is appearing on the far left of the screen and I would like it to be contained inside the black box on the playing field. My code is as follows:

private var playerScore : int;
var scoreStyle : GUIStyle;

function Start () {
	renderer.material.color = Color.black;
}

function Update () {

}

function OnGUI() {
	GUILayout.BeginArea(Rect(10,10, Screen.width/2, Screen.height/2));
	GUILayout.Box(playerScore.ToString(), scoreStyle);
	GUILayout.EndArea();
}

function Score() {
	playerScore = 0000;
}


function OnTriggerEnter(collision:Collider) {
	if (collision.gameObject.tag == "Zs")
	{
		playerScore += 10;
	}
}

Thank you all in advance for your help on this subject and I hope the community can be of assistance. Much appreciated again.

  • Slyy

This black box that is highlighted, how have you created this? It looks like a drawing? The picture isn’t very clear.

Your piece of code that you have used to create your area:

GUILayout.BeginArea(Rect(10,10, Screen.width/2, Screen.height/2));

Your Rect will start 10 from the left and 10 down in screen coordinates, with a width and height that is half the screen width and height respectively. I cant see any code that has created the box you have highlighted.

GUILayout.Box(playerScore.ToString(), scoreStyle);

Starts in the area exactly where you have told it to. Take a look at the docs again and move your area or box to fit where you need, keep in mind its going to be a different place for different screen resolutions.

http://docs.unity3d.com/Documentation/ScriptReference/GUILayout.BeginArea.html