- Home /
Question by
S_Byrnes · Mar 28, 2014 at 12:28 AM ·
c#guileaderboardskin
Leaderboard GUISkin?
Hey guys, I need some help getting my leaderboard to match with the theme of my game, at the moment I have the leaderboard working correctly, and appearing, but not with my GUI skin, it's only the default, here's what I have so far:
using UnityEngine;
using System.Collections.Generic;
public class LeaderBoardSample : MonoBehaviour {
float startTime = 10.0f;
float timeLeft = 0.0f;
public GUISkin guiSkin;
Rect windowRect = new Rect (0, 0, 620, 520);
string playerName = "";
string code = "";
enum gameState {
waiting,
running,
enterscore,
leaderboard
};
gameState gs;
// Reference to the dreamloLeaderboard prefab in the scene
dreamloLeaderBoard dl;
dreamloPromoCode pc;
void Start ()
{
// get the reference here...
this.dl = dreamloLeaderBoard.GetSceneDreamloLeaderboard();
// get the other reference here
this.pc = dreamloPromoCode.GetSceneDreamloPromoCode();
this.timeLeft = startTime;
this.gs = gameState.waiting;
}
void Update ()
{
if (this.gs == gameState.running)
{
this.gs = gameState.enterscore;
}
}
void OnGUI()
{
GUI.skin = guiSkin;
GUILayoutOption[] width200 = new GUILayoutOption[] {GUILayout.Width(200)};
float width = 400; // Make this wider to add more columns
float height = 200;
Rect r = new Rect((Screen.width / 2) - (width / 2), (Screen.height / 2) - (height), width, height);
GUILayout.BeginArea(r, new GUIStyle("box"));
GUILayout.BeginVertical();
if (this.gs == gameState.waiting || this.gs == gameState.running)
{
this.gs = gameState.running;
GUILayout.Label("Total Score: " + GameLogicScript.score);
}
if (this.gs == gameState.enterscore)
{
GUILayout.Label("Total Score: " + GameLogicScript.score);
GUILayout.BeginHorizontal();
GUILayout.Label("Your Name: ");
this.playerName = GUILayout.TextField(this.playerName, width200);
if (GUILayout.Button("Save Score"))
{
// add the score...
if (dl.publicCode == "") Debug.LogError("You forgot to set the publicCode variable");
if (dl.privateCode == "") Debug.LogError("You forgot to set the privateCode variable");
dl.AddScore(this.playerName, GameLogicScript.score);
this.gs = gameState.leaderboard;
}
GUILayout.EndHorizontal();
}
if (this.gs == gameState.leaderboard)
{
GUILayout.Label("High Scores:");
List<dreamloLeaderBoard.Score> scoreList = dl.ToListHighToLow();
if (scoreList == null)
{
GUILayout.Label("(loading...)");
}
else
{
int maxToDisplay = 20;
int count = 0;
foreach (dreamloLeaderBoard.Score currentScore in scoreList)
{
count++;
GUILayout.BeginHorizontal();
GUILayout.Label(currentScore.playerName, width200);
GUILayout.Label(currentScore.score.ToString(), width200);
GUILayout.EndHorizontal();
if (count >= maxToDisplay) break;
}
}
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
I essentially need to present these kind of like the code bellow, where the code above replaces my buttons bellow:
using UnityEngine;
using System.Collections;
public class GameOver : MonoBehaviour {
public GUISkin guiSkin;
Rect windowRect = new Rect (0, 0, 620, 520);
private bool toggleTxt = false;
string stringToEdit = "Text Label";
float hSliderValue = 0.0f;
float vSliderValue = 0.0f;
private float hSbarValuet;
private float vSbarValue;
private Vector2 scrollPosition = Vector2.zero;
void Start (){
Time.timeScale = 1.0f;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
windowRect.x = (Screen.width - windowRect.width)/2;
windowRect.y = (Screen.height - windowRect.height)/2;
}
void OnGUI (){
GUI.skin = guiSkin;
windowRect = GUI.Window (0, windowRect, DoMyWindow, "Game Over");
}
void DoMyWindow ( int windowID ){
GUI.Button (new Rect (140, 50, 340, 50), "Score: " + GameLogicScript.score);
if (GUI.Button (new Rect (140, 120, 340, 50), "Post Score"))
Application.LoadLevel ("Post Score");
if (GUI.Button ( new Rect(140,190,340,50), "Restart"))
Application.LoadLevel ("TestScene1");
if (GUI.Button ( new Rect(140,260,340,50), "Main Menu"))
Application.LoadLevel ("Menu");
if (GUI.Button ( new Rect(140,330,340,50), "Quit"))
Application.Quit ();
}
}
I hope I made that clear, thanks in advanced!
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Working With GUI 1 Answer
Is There A Way To Make Sprites Clickable? 1 Answer
In-Game GUI buttons don't work 2 Answers