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 Facepalm · Feb 05, 2012 at 11:36 PM · buttonimageresizestyle

Resize a button while it's active

I want to resize a button while it's being pressed. At the moment I have a style with no image as background (_style.normal.background = null) and Buttons are being drawn using some images and that style. I would like to define a size of the buttons being displayed for the same layer but in the active state instead of normal and I have no idea how to do it.

code:

 public class Buildings : MainSubPanel {
     private Rect[] _boxes;
     private GUIStyle _style;
     private Texture2D[] _icons;
     
     public Buildings(Swapper swapper, Texture2D[] icons) : base(swapper){
         int i = 0;
         int n = 0;
         int shift = 10;
         _icons = icons;
         _boxes = new Rect[12];
         _style = new GUIStyle();
         _style.normal.background = null;
         while(i < 3){
             while(n < 4){
                 _boxes[i*4+n] = new Rect(15+shift+shift*n+50*n, 15+shift+shift*i+i*50, 50, 50);
                 ++n;
             }
             n = 0;
             ++i;
         }
     }
     
     public override void draw(){
         int i = 0;
         while(i<_icons.Length){
             if(GUI.Button(_boxes[i], _icons[i], _style)){
                 _swapper.swap(i);
             }
             i++;
         }
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Feb 06, 2012 at 12:43 AM

You could use a different rect for the active button. It's going to look weird though, as the active state in a button, when it's not a selection grid (and even the the state is OnNormal) is very fast, just the time of a clic.

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 Facepalm · Feb 06, 2012 at 01:28 AM 0
Share

Could you explain how does SelectionGrid works? It just creates a grid of images?

avatar image Berenger · Feb 06, 2012 at 02:29 AM 0
Share

A grid of buttons actually. The difference being that, when you clic one, it stays activated and deactive the previous one. For example, if you have a selection grid with those elements : "Banana", "Apple", "Strawberry", you can choose which one you're going to eat (only one $$anonymous$$d you !). For the script part, check out the manual.

avatar image Facepalm · Feb 06, 2012 at 03:35 AM 0
Share

Ok, I see. But I'm not sure if that's what I want. Here is a sample of my idea, so I hope anyone knows how to realize it without creating X images for active backgrounds or X additional styles (new style for every button).

Sample: on the right part of image 2nd button is being pressed but not released yet -> http://img215.imageshack.us/img215/9855/29395185.jpg

P.S.: all the images will be different as it's obvious

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i set screenshot image of Scene2 to Scene1(Button) in unity. Thanks in adavance 1 Answer

UI drag and drop 1 Answer

Button Images Disappearing 1 Answer

Button's sprite swap works fine but it doesn't change the related image's source image! why? 1 Answer

polygon collider 2d problem 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