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 MichaelARoberts · Aug 12, 2014 at 05:09 AM · guibuttonstringboxdialogue

Problems with simple dialogue

Been trying to get this bit of code working. I have it attached to empty game object that's a child of the "Main Camera". The idea is to have a GUI box that is filled with a string that contains the text of the player you're talking to. Then the player can select smaller buttons beneath it that will change the text according to what is said. My problem is that the string in GUI.Box text starts as off as "Thank You." instead of "Hello There!". Not sure of the issue, would love a resolution (preferably in javascript). Thanks.

 #pragma strict
 
 var Hello : String = "Hello there!";
 
 function OnGUI ()
 {
 
 GUI.Box(Rect(0,Screen.height-150,Screen.width,50), Hello );
 
     if (GUI.Button ( Rect (20,Screen.height-90,225,50), "Good Day."));
     {
     Hello = "Thank you.";
     }
 }
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 · Aug 12, 2014 at 04:27 AM 0
Share

This line:

 if (GUI.Button ( Rect (20,Screen.height-90,225,50), "Good Day."));

See the semicolon at the end of that line? Get rid of it.

Explanation: the semicolon "ends" the if statement, which means it no longer controls whatever block of code is after it. In rare cases, experienced programmers actually want that behaviour, but for now it's usually best to assume that semicolons should never, ever go directly after loops or conditionals.

Don't feel silly about missing that, either. That has to be one of the worst gotchas in today's program$$anonymous$$g languages.

I'm hesitant to let this through the moderation queue because it's a frequently asked question. It's not a bad question, we're just trying to cut down on the number of duplicate threads in this area of the site. If you have anything else to add, feel free to comment here; if not, I'll drop the question from the queue in a little while.

If you can't find help, here, you can always try the forums or look up some tutorials online.

avatar image MichaelARoberts · Aug 12, 2014 at 04:40 AM 0
Share

Thanks for the help!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

changing GUI Button text with a string array 2 Answers

How do I set a GUI button's text using a string from another script? 0 Answers

Create GUI based on an array 2 Answers

Remove GUI Box Drawing? 1 Answer

GUI.Button on MouseHover 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