- Home /
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 [1]: /storage/temp/3996-scorehelpunity.jpeg
Answer by T27M · Oct 08, 2012 at 10:19 PM
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
That's what I thought about the area...but also why is it only showing 1 zero ins$$anonymous$$d of the 0000 that I have set as the player score? And the box that is highlighted in the picture is a Cube GameObject which now that I'm thinking about it, doesn't really make sense to apply a score to. Or can that still work?
When you say apply your score to it what do you mean? The object the script is attached to ?
Also it shows 0 because 0000 is just another way of saying 0. You need to format your string if you want more than one 0.
When I say apply my score to it, I do indeed mean the object that script is attached to...I also did not know that it would revert to that. Thank you