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 skinnysimmons · Jul 23, 2014 at 05:44 PM · guibuttonclickstyle

After Adding GUIStyle to GUI.Button, it is no longer clickable

I want to make a button out of the font that I have. I set up the javascript variable

 var comicStyle : GUIStyle;

(and in the inspector I've edited the font, font size, normal color, and Alignment, everything else is default)

if I use this line of code:

 if(GUI.Button(Rect(200, 200, 300, 75), "feedback", comicStyle))
 {
     print("You Clicked the Feedback button");
 } 

it draws the words "feedback" on the screen right where I want it, but I can't click it.

if I remove the style argument from the GUI.Button, like this...

 if(GUI.Button(Rect(200, 200, 300, 75), "feedback"))
 {
     print("You Clicked the Feedback button");
 }

it makes a gray button rectangle with the word "feedback" in it, that I can click, and see the print command execute in the console.

My question is, is there something I'm not setting correctly in my style that is allowing this to be "click-able"? or am I totally off?

I can easily make a sprite out of the word, but I'm looking to reduce the amount of images in my game with concerns of file size.

Thanks in advance!!!

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 skinnysimmons · Jul 23, 2014 at 08:50 PM 0
Share

nope, the "IF" statement it in the OnGUI() function, like so.

 function OnGUI()
 {
     if(GUI.Button(Rect(200, 200, 300, 75), "feedback"))
     {
     print("You Clicked the Feedback button");
     }
 }

it works if I simply do not include the "style" which makes me think the style is making it no longer function as a button :/ But I can't find any info about that. There is some about GUISkin, but i can't seem to find a way that it makes a difference.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 23, 2014 at 09:27 PM

Well, you shouldn't declare a GUIStyle that way. It's better to create a GUISkin and use that one. In the skin asset you could edit the Button style or add a custom style at the bottom and use that one. To use a GUISkin you just declare a public variable of type GUISkin and inside OnGUI you set your skin as the current. Something like that:

 var mySkin : GUISkin;
 
 function OnGUI()
 {
     GUI.skin = mySkin;
     // Your GUI stuff
 
 }

Note: If you use a custom style and your skin is "active" you can simply use the style name as string, like so:

 GUI.skin = mySkin;
 if(GUI.Button(Rect(200, 200, 300, 75), "feedback", "feedbackStyleName"))
 {

You can also use any other style like this. This would draw a button with the label style:

 if(GUI.Button(Rect(200, 200, 300, 75), "feedback", "label"))
 {
Comment
Add comment · Show 1 · 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 skinnysimmons · Jul 24, 2014 at 04:12 PM 0
Share

on thing that also seemed to work, is that the values "300" for the GUI element X width, was smaller than the Styles Font size. So there actually WAS a button there, i just couldn't see it because the Style had no background image set up. Once i through a stand in square texture, I was able to see the "hit box" for the button, and adjust my code to make it fit the text.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUIStyle not working on GUI.Button 4 Answers

click on GUI button goes through to a collider... 0 Answers

Change GUI.Box color when click button 1 Answer

GUI.Button press (not click) 3 Answers

Stop clicking through a GUI window 2 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