Hello guys. I’ve been programming this game and lately i was working on Score Grid. Everything seems ok, but the GUI.Window not showing at all, or without SelectionGrid. It seems i can’t figure it out by myself, so i need your help!
Here’s the code:
#pragma strict
var Vardas : String; //vardas stands for Name (this one is for the player to type by himself))
var Vardas1 : String[]; //this one is for Top 4 to be saved in PlayerPrefs
var Laikas : int; //laikas stands for Time
var Laikas1 : int[];
var selGridInt : int = 0;
var selStrings : String[] = [Vardas1[0], Laikas1[0], Vardas1[1], Laikas1[1]]; //i made this like in unity docs
var selGridInt2 : int = 1;
var selStrings2 : String[] = [Vardas1[2], Laikas1[2], Vardas1[3], Laikas1[3]];
//------------------ This part is not important -----------------
var timer : float = 13;
var MainMenu : Rect = Rect(10, 10, Screen.width, Screen.height);
static var completed : boolean = false;
private var paused : boolean = false;
private var A : boolean = false;
private var B : boolean = false;
function Start() {
//-------------------------------------------
//i get all the prefs
Vardas1[0] = PlayerPrefs.GetString("Vardas1");
Vardas1[1] = PlayerPrefs.GetString("Vardas2");
Vardas1[2] = PlayerPrefs.GetString("Vardas3");
Vardas1[3] = PlayerPrefs.GetString("Vardas4");
Laikas1[0] = PlayerPrefs.GetInt("Laikas1");
Laikas1[1] = PlayerPrefs.GetInt("Laikas2");
Laikas1[2] = PlayerPrefs.GetInt("Laikas3");
Laikas1[3] = PlayerPrefs.GetInt("Laikas4");
//-------------------------------------------
}
//------------------ This part is not important -----------------
//laiko skaiciavimas
function Update () {
Screen.showCursor = false;
if(timer > 0)
timer -= Time.deltaTime;
if(timer <= 0) {
completed = true;
}
//--------------------
//pause menu
if(paused) {
Time.timeScale = 0;
Screen.showCursor = true;
Screen.lockCursor = false;
}
else {
Time.timeScale = 1;
Screen.showCursor = false;
Screen.lockCursor = true;
}
if(completed == true)
paused = true;
}
//-------------------------------first for cycle is for finding the place for our player to be in the Top 4
//lenteles generavimas
private var kelintas : int;
if(A) {
for(var i = 0; i < 4; i++) //radimas rezultato vietos lenteleje
if(Laikas1[i] > Laikas)
kelintas++;
//---- when whe have place, put it in there
//iterpia i masyva kelintas vietoje reiksme
for(var c = 4; c > kelintas; c--) {
Laikas1[c] = Laikas1[c-1];
Vardas1[c] = Vardas1[c-1];
}
Laikas1[kelintas] = Laikas;
Vardas1[kelintas] = Vardas;
B = true; //and after all of that, show the Top 4 window
}
//---------------------
//GUI funkcijos
function OnGUI(){
if(paused A == false) { //if paused then show the Gui to enter Name
Scoreenter();
}
if(A B) { //if the table has been generated then show the table
//one more problem is that the first Rect parametres doesnt change anything, it still shows gui almost from the middle of the screen no matter what
GUI.Window(0, MainMenu, Lentele, "TOP 4 SCORES");
}
}
function Scoreenter() {
GUI.Box(Rect(Screen.width * 0.4f,Screen.height * 0.5f,200,50), " Type in your name: ");
Vardas = GUI.TextField (Rect (Screen.width * 0.4f, Screen.height * 0.55f, 200, 20), Vardas, 20);
if(GUILayout.Button("Continue", GUILayout.Width(Screen.width), GUILayout.Height(Screen.height * 0.5f))){
A = true;
}
}
//--------------The problem is here--------------
//i need 8 buttons (4 for names and 4 for times)(why buttons not text box? because it's easyer)
function Lentele(){
selGridInt = GUI.SelectionGrid (Rect (10, 20, Screen.width/5, Screen.height/5), selGridInt, selStrings, 2);
selGridInt2 = GUI.SelectionGrid (Rect (10, 20, Screen.width/2.5, Screen.height/2.5), selGridInt2, selStrings2, 2);
}
Thank you for any help.