Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GreenLimeLight · Jun 14, 2011 at 03:00 AM · buttontoggleguiskin

GUISkin & Scripting

Thus far, I've created a new GUISkin and under the GUIStyle Button, I've imported and placed 3 png files under Normal bg, Hover bg and Active bg.

I created a new Javascript with this codes:

var toolSkin: GUISkin; var Button = true;

  function OnGUI () {
      GUI.skin = toolSkin;
      GUI.Button (Rect (0,500,230,200), "");
  }

This allows the button to appear and gives 3 different forms when it is untouched, when I get near to the button and when I click on it.

However, how do I reduce the space around the button so that it only changes when I hover over it and not when I'm hovering around the space of the button? Also, how do I allow the active bg to stay active once I clicked on it, and revert back to hovering state once I unclicked it?

Any help would be glady appreciated, thank you!

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 jahroy · Jun 14, 2011 at 07:29 AM

You can also draw a toggle button and use the button style that you already altered like this:

 GUI.Toggle(Rect(0, 0, 100, 100), isToggleOn, "button");

You can apply any style you want to a gui control.

You can also make a small image stretch to fit the rectangle by using the GUIStyle.border property.

By setting the border to (1, 1, 1, 1) you tell the GUI to stretch everything but the outermost pixel of your texture to fit the rectangle.

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 GreenLimeLight · Jun 14, 2011 at 08:35 AM 0
Share

Thanks for your help!

What I've accomplished thus far is setting up 7 buttons which can go into their normal state, hover state and active state. Also, I've re-edit the canvas size for my pentagon buttons so that the rectangular background around it originally is smaller in size now.

However, the problem now is that when I click on one button, all 7 light up. If you don't $$anonymous$$d, could you look through this question as well? "http://answers.unity3d.com/questions/129813/using-guitoggle-to-onoff-buttons.html" It's alright though if you're busy!

avatar image jahroy · Jun 14, 2011 at 05:15 PM 1
Share

I just posted an answer to your other question. Good luck!

avatar image GreenLimeLight · Jun 15, 2011 at 03:17 AM 0
Share

Awesome! Tyvm! :D

avatar image
1

Answer by Bunny83 · Jun 14, 2011 at 04:36 AM

What do you mean by "unclicked"? a Button is not a Toggle.

And to your hover problem you don't get "near" the button, you're ON the button. You've made the button 230x200 ... I guess the background texture is smaller than your actual button...

GUI elements are always rectangular so there's no easy way around that fact (if your image is circle-shaped with alpha or something like that)

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 GreenLimeLight · Jun 14, 2011 at 05:00 AM 0
Share

So assu$$anonymous$$g under GUIStyle Toggle, I switch over the PNG images to their respective places, how would I get the button to react respectively?

Thanks for that answer for the size of the button! I'd just have to adjust my PSD file to enlarge it.

Edit: OH, I've finally got it! Thanks Bunny for your help! :D

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

Using GUIToggle to on/off buttons! 5 Answers

Whats wrong with my GUI.Toggle? 2 Answers

GUI Button which looks like a Toggle 0 Answers

How to reset the state of other buttons when clicking on one of them 0 Answers

UI Button should stay highlighted on click 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