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 Jacko1123 · Jan 04, 2014 at 12:23 PM · project

Switch statement in If in GUI function

For learning purposes, I'm basically making a Taboo game version, I have a OnGUI function, with a if statement and a switch statement inside.

I have this code with a few Debug.Log to test it, everything works just except for the GUI.Label's showing up as supposed.` function OnGUI() {

 GUI.Box(Rect(24, 29, 332, 372), "", boxStyle);
 if(GUI.Button(new Rect(22,401, 50, 50),"Pass"))
 {
     Debug.Log("Test");
     var randomWord = Random.Range(0, wordHeader.length);   
     var word = wordHeader[randomWord];
     Debug.Log(word);
     switch(word)
     {
         case "Carrot":
             Debug.Log("c"); 
              GUI.Label(Rect(0,38,Screen.width,Screen.height),"Carrot", labelStyle);
              GUI.Label(Rect(0,160,Screen.width,Screen.height),"Orange", badWordsStyle);
              GUI.Label(Rect(0,220,Screen.width,Screen.height),"Vegetable", badWordsStyle);
              GUI.Label(Rect(0,280,Screen.width,Screen.height),"Bunny", badWordsStyle);
              GUI.Label(Rect(0,340,Screen.width,Screen.height),"Crunchy", badWordsStyle);        
             break;'

However without the If statement, it seems to loop through the array every frame instead of just once, I think I have a solution for this part, but I can't figure out how to get the GUI.Label's to show with the if statement in place, all the Debug.Log's work fine, thanks in advance, any questions I'll be glad to answer

Comment
Add comment · Show 2
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 rutter · Jan 04, 2014 at 12:30 PM 0
Share

Sorry, but I'm not sure if I understand the question. Because OnGUI() is called every frame, you probably only want to select a new word on frames where the user has requested that (say, by hitting that button). Is your switch supposed to show only the current word? If so, you'll need a distinct case for each word... though, if your words are already user-friendly, you might as well just draw the word directly, and skip the switch.

avatar image Jacko1123 · Jan 04, 2014 at 01:48 PM 0
Share

Oh of course, sorry I had a little moment there -.- I forgot OnGUI was every frame. Thanks for the quick reply :) I'll change my code around :)

0 Replies

· Add your reply
  • Sort: 

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How do you use Unity Remote on an Android? 0 Answers

Update unity can't find old projects 1 Answer

unty wont work! 3 Answers

Where to get bootcamp demo project (again)? 4 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