- Home /
disable GUI when loading is done
I'm making a random generated horror game and during the loading screen the world is generated. Its basically all in the same scene (except for the main menu). But i have a problem, when my loader hits 100% the GUI wont disappear. i know a script would be nice but every time i try to paste the code in the "< pre > < code >" section its all in the same line. I basically have two troubles and need help with both of them...
Paste your code, select it and hit the 101010 button.
Answer by FakeBerenger · Nov 17, 2012 at 01:37 PM
You can disable the script displaying the loading progress, or use a boolean inside the OnGUI function. I can't be more accurate without code.
Answer by martinhalldin · Nov 17, 2012 at 01:37 PM
var updateString: String = "";
function UpdateProgress() {
var progress:float = tileCounter/(height*width*6.0);
updateString = progress.ToString("Loading: #0%");
if (progress.ToString("Loading: #10%"));
GUI.enabled = false;
}
function OnGUI(){
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (Screen.width /2 - 100,Screen.height /2 - 0,300,25),updateString );
}
heres the code, i only want to disable the gui part
Answer by Owen-Reynolds · Nov 17, 2012 at 03:23 PM
The basic method to turn on/off any OnGUI element is to toss an `if` in front of your GUI commands:
if(!progress.isDone) {
GUI.Box( .....
}
Probably a better way is to have the OnGUI script be on another gameObject, which is destroyed when you finish loading.
its not that simple, i have a "maze generator" script and the gui loader in the same script. its quite complicated but i can give you the whole code
Can put the $$anonymous$$aze variable in the real script and split off all the "not needed after maze is made" into another script on an empty prefab. Spawn to make the maze. It would have a link to the "real" script and use `$$anonymous$$S.maze` ins$$anonymous$$d of just maze.
Answer by martinhalldin · Nov 17, 2012 at 03:35 PM
// Changed this to bypass the deprecated methods transitioning to Unity 2.6 : ACF
var next:Transform;
// maze dimensions
var height:int = 12;
var width:int = 12;
var mainMenuSceneName : String;
var pauseMenuFont : Font;
private var pauseEnabled = false;
private var maze;
private var tileCounter = 0;
private var facingDown:Quaternion = Quaternion.Euler(180,0,0);
class Room {
var east:Transform;
var west:Transform;
var north:Transform;
var south:Transform;
}
function Start() {
maze = new Array(width*height);
yield StartCoroutine("InstantiateFloor");
yield StartCoroutine("InstantiateWalls");
if (next != null) {
next.gameObject.active = true;
}
// Added a Call to actually Make your Maze : ACF
MakeMaze();
}
function InstantiateWalls() {
var mid = tileSize/2;
var pos = new Vector3(0,mid,0);
for (var x:int =0; x< width; ++x) {
var xpos:int = x*tileSize;
for (var y:int =0; y< height; ++y) {
var ypos:int = y*tileSize;
var room = new Room();
pos.x = xpos;
pos.z = ypos-mid;
// BlLENDER fix
if(tile.rotation.eulerAngles.x == 270){
room.south = InstantiateTile(pos,tile.rotation);
room.south.Rotate(90,0,0);
pos.x = xpos-mid;
pos.z = ypos;
room.west = InstantiateTile(pos,tile.rotation);
room.west.Rotate(90,0,0);
room.west.Rotate(0,90,0);
pos.x = xpos;
pos.z = ypos+mid;
room.north = InstantiateTile(pos,tile.rotation);
room.north.Rotate(90,0,0);
room.north.Rotate(0,180,0);
pos.x = xpos+mid;
pos.z = ypos;
room.east =InstantiateTile(pos,tile.rotation);
room.east.Rotate(90,0,0);
room.east.Rotate(0,270,0);
} else {
room.south = InstantiateTile(pos,tile.rotation);
room.south.Rotate(90,0,0);
pos.x = xpos-mid;
pos.z = ypos;
room.west = InstantiateTile(pos,tile.rotation);
room.west.Rotate(90,90,0);
pos.x = xpos;
pos.z = ypos+mid;
room.north = InstantiateTile(pos,tile.rotation);
room.north.Rotate(90,180,0);
pos.x = xpos+mid;
pos.z = ypos;
room.east =InstantiateTile(pos,tile.rotation);
room.east.Rotate(90,270,0);
}
maze[MazeIndex(x,y)]=room;
UpdateProgress();
yield;
}
}
}
// floor and ceiling
function InstantiateFloor() {
//Instead of assuming a zeroed prefab, let's grab the pos and rot of our prefab!
var floorpos:Vector3 = tile.position;
for (var x:int=0; x< width; ++x) {
floorpos.x = x*tileSize;
for (var y:int=0; y< height; ++y) {
floorpos.z = y*tileSize;
floorpos.y = 0;
InstantiateTile(floorpos,tile.rotation);
floorpos.y = tileSize;
InstantiateTile(floorpos,tile.rotation * facingDown);
UpdateProgress();
yield;
}
}
}
var updateString: String = "";
function UpdateProgress() {
var progress:float = tileCounter/(height*width*6.0);
updateString = progress.ToString("Loading: #0%");
}
function OnGUI(){
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (0, 0, 3000, 3000),updateString);
GUI.Box (Rect (Screen.width /2 - 100 ,Screen.height /2 - 0,200,50),updateString );
}
function InstantiateTile(pos:Vector3,rot:Quaternion):Transform {
++tileCounter;
return Instantiate(tile,pos,rot);
}
function MakeMaze() {
ClearMaze();
SetOuterWalls();
SubDivideMaze(0,width-1,0,height-1);
}
function ClearMaze() {
for (var x:int=0; x< width; ++x) {
for (var y:int=0; y< height; ++y) {
maze[MazeIndex(x,y)].west.active = false;
maze[MazeIndex(x,y)].east.active = false;
maze[MazeIndex(x,y)].north.active = false;
maze[MazeIndex(x,y)].south.active = false;
}
}
}
function SubDivideMaze(left,right,bottom,top) {
if (left!=right && bottom != top) {
var x:int = Random.Range(left,right);
var leftdoor:int = Random.Range(left,x+1);
var rightdoor:int = Random.Range(x+1,right+1);
var y:int = Random.Range(bottom,top);
var bottomdoor:int = Random.Range(bottom,y+1);
var topdoor:int = Random.Range(y+1,top+1);
AddNorthWall(left,right,y);
AddEastWall(bottom,top,x);
var doors = Random.value;
if (doors < 0.25) {
SetNorthWall(MazeIndex(leftdoor,y),false);
SetNorthWall(MazeIndex(rightdoor,y),false);
SetEastWall(MazeIndex(x,bottomdoor),false);
} else {
if (doors < 0.5) {
SetNorthWall(MazeIndex(leftdoor,y),false);
SetNorthWall(MazeIndex(rightdoor,y),false);
SetEastWall(MazeIndex(x,topdoor),false);
} else {
if (doors < 0.75) {
SetNorthWall(MazeIndex(rightdoor,y),false);
SetEastWall(MazeIndex(x,bottomdoor),false);
SetEastWall(MazeIndex(x,topdoor),false);
} else {
SetNorthWall(MazeIndex(leftdoor,y),false);
SetEastWall(MazeIndex(x,bottomdoor),false);
SetEastWall(MazeIndex(x,topdoor),false);
}
}
}
SubDivideMaze(left,x,y+1,top);
SubDivideMaze(x+1,right,y+1,top);
SubDivideMaze(left,x,bottom,y);
SubDivideMaze(x+1,right,bottom,y);
}
}
function SetOuterWalls() {
AddNorthWall(0,width-1,height-1);
AddSouthWall(0,width-1,0);
AddEastWall(0,height-1,width-1);
AddWestWall(0,height-1,0);
SetNorthWall(MazeIndex(width-1,height-1),false);
}
function MazeIndex(x:int,y:int):int {
return y*width+x;
}
function SetNorthWall(room,value) {
maze[room].north.active = value;
var neighbor:int = RoomNorth(room);
if (neighbor !=-1) {
maze[neighbor].south.active = value;
}
}
function SetSouthWall(room,value) {
maze[room].south.active = value;
var neighbor:int = RoomSouth(room);
if (neighbor !=-1) {
maze[neighbor].north.active = value;
}
}
function SetEastWall(room,value) {
maze[room].east.active = value;
var neighbor:int = RoomEast(room);
if (neighbor !=-1) {
maze[neighbor].west.active = value;
}
}
function SetWestWall(room,value) {
maze[room].west.active = value;
var neighbor:int = RoomWest(room);
if (neighbor !=-1) {
maze[neighbor].east.active = value;
}
}
function AddNorthWall(left:int,right:int,y:int) {
for (var hwall:int = left; hwall<=right; ++hwall) {
SetNorthWall(MazeIndex(hwall,y),true);
}
}
function AddEastWall(bottom:int,top:int,x:int) {
for (var vwall:int = bottom; vwall<=top; ++vwall) {
SetEastWall(MazeIndex(x,vwall),true);
}
}
function AddSouthWall(left:int,right:int,y:int) {
for (var hwall:int = left; hwall<=right; ++hwall) {
SetSouthWall(MazeIndex(hwall,y),true);
}
}
function AddWestWall(bottom:int,top:int,x:int) {
for (var vwall:int = bottom; vwall<=top; ++vwall) {
SetWestWall(MazeIndex(x,vwall),true);
}
}
function RoomEast(index:int) {
var y:int = index/width;
var x:int = index-y*width;
if (x==width-1) {
return -1;
} else {
return MazeIndex(x+1,y);
}
}
function RoomWest(index:int) {
var y:int = index/width;
var x:int = index-y*width;
if (x==0) {
return -1;
} else {
return MazeIndex(x-1,y);
}
}
function RoomNorth(index:int) {
var y:int = index/width;
var x:int = index-y*width;
if (y==height-1) {
return -1;
} else {
return MazeIndex(x,y+1);
}
}
function RoomSouth(index:int) {
var y:int = index/width;
var x:int = index-y*width;
if (y==0) {
return -1;
} else {
return MazeIndex(x,y-1);
}
}
function GetRoom(x:int,y:int) {
return maze[MazeIndex(x,y)];
}
Answer by martinhalldin · Nov 17, 2012 at 08:00 PM
I think i know what to put but im not sure where:
if (Random_Maze.isDone){
GUI.enabled = false;
}
Can anyone help?
i still haven't found the right script, could anybody help?
GUI.enabled (must be called inside OnGUI scope !) is going to render all following GUI of the current scope grayish, and the user won't be able to interact with it. But it will be displayed.
but is there a way to "hide" it or something like that?
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Rigidbody Gravity scripting question (Javascript Answers Only!) 3 Answers
[Solved]GUI won't pop out 1 Answer
Making a progress bar a different color (Java) 0 Answers
Can't move GUI 1 Answer