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 Dann858 · Jan 20, 2013 at 06:23 PM · c#guitutorial

GUI functions switching

Hello, I'm new to C# and Unity and to scripting in general. I've made a decent Main Menu that is able to bring the player to a tutorial world. Now in this tutorial world I want to call GUI functions to explain to the player how everything works. But how can I switch the text a GUI.Box is displaying?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Professor Snake · Jan 20, 2013 at 06:56 PM

You can use simple if statements with booleans. In order to show a group of GUI elements, you use something like the code below and modify the booleans to determine which message(s) to show:

 var showMessage:boolean[];
 
 function OnGUI(){
 if(showMessage[0]){
 //Any GUI you want to show here.
 }
 if(showMessage[1]){
 //other GUI elements here.
 }
 //more checks here
 
 }

Alternatively, you could have one group of GUI events with modifiable contents, and just modify whether the GUI is visible and the contents:

 var showGUI:boolean=false;
 var labelText:String="Hello, and welcome to my game";
 var label2Text:String="This is a training level.";
 function OnGUI(){
 if(showGUI){
 GUI.Label(Rect(0,0,100,100),labelText);
 GUI.Label(Rect(0,100,100,100),label2Text);
 }

}

Comment
Add comment · Show 4 · 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 Dann858 · Jan 20, 2013 at 07:22 PM 0
Share

Things is. I'm writing in C#. As far as I see this is Java. I do understand it a little bit, but not totally.

avatar image Professor Snake · Jan 20, 2013 at 08:19 PM 0
Share

You can easily convert the code by changing "var name:Type" to "Type name" and "function name()" to "void name()". Besides, the code was there to give you an idea of how it works and encourage you to write your own version of it, not do the entire work for you.

avatar image Dann858 · Jan 21, 2013 at 01:52 PM 0
Share

I'm sorry, I've tried to understand the script but I simply can't. I tried: public bool TextBox1 = GUI.Box(new Recht(etc.), Text1); public string Text1 = "Welcome to ...."; But it just doesn't seem to work. I can't put it into another function.

$$anonymous$$y idea is to say: public void OnLevelWasLoaded(int level) { if(level = 1) Time.timeScale = 0; }

public void StartGame() { if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Return)) Time.timeScale = 1; TextBox1 = false; }

avatar image Professor Snake · Jan 21, 2013 at 02:15 PM 0
Share

There is no reason to Assign a GUI.Box to a boolean. You can keep your loading code and add void OnGUI(){ if(textbox1){ //GUI.Box call here}}

avatar image
0

Answer by Dann858 · Jan 21, 2013 at 02:08 PM

I'm sorry, I've tried to understand the script but I simply can't. I tried: public bool TextBox1 = GUI.Box(new Recht(etc.), Text1); public string Text1 = "Welcome to ...."; But it just doesn't seem to work. I can't put it into another function.

My idea is to say:

 public void OnLevelWasLoaded(int level) {
    if(level = 1)
      Time.timeScale = 0;
 }
 
 public void StartGame() {
    if(Input.GetKeyUp(KeyCode.Return))
       Time.timeScale = 1;
       TextBox1 = false;
 }
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 Professor Snake · Jan 21, 2013 at 02:17 PM 0
Share

You also shouldn't post comments as answers.

avatar image Dann858 · Jan 21, 2013 at 02:24 PM 0
Share

I know, But the add comment didn't allow me to put a code in my response. Like when you give an answer or ask a question.

avatar image Bunny83 · Jan 21, 2013 at 04:15 PM 0
Share

It does allow you to put code in your comment, you just have to format it like in the answer field:

  • Add an empty line before and after the code block

  • indent every line within the code block by at least 4 spaces

That's all. Here i copied your code example:

 public void OnLevelWasLoaded(int level) {
    if(level = 1)
      Time.timeScale = 0;
 }
 
 public void StartGame() {
    if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Return))
       Time.timeScale = 1;
       TextBox1 = false;
 }


If you are too lazy to format it "manually", just write the comment in the answer field and when you're done, copy it into the comment field.

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

Distribute terrain in zones 3 Answers

Making a Tutorial in th emiddle of screen and more efficiant 1 Answer

Multiple Cars not working 1 Answer

When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer

Handling Undo/REdo in EditorWindow when editing DB record. 0 Answers


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