Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by martinhalldin · Nov 17, 2012 at 01:17 PM · javascriptguiloadinghorrortwo

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...

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FakeBerenger · Nov 17, 2012 at 01:36 PM 0
Share

Paste your code, select it and hit the 101010 button.

5 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image martinhalldin · Nov 17, 2012 at 03:33 PM 0
Share

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

avatar image Owen-Reynolds · Nov 18, 2012 at 05:26 AM 0
Share

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.

avatar image
0

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)];
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image martinhalldin · Nov 18, 2012 at 12:16 AM 0
Share

i still haven't found the right script, could anybody help?

avatar image FakeBerenger · Nov 18, 2012 at 10:36 AM 0
Share

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.

avatar image martinhalldin · Nov 18, 2012 at 10:38 AM 0
Share

but is there a way to "hide" it or something like that?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges