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 shay4545 · Dec 14, 2014 at 03:48 PM · c#androidguigui-button

How to make a GUI Button shrink when pressed

Is there any way to make it so when you click the gui button it gets a little smaller and then when you let go it goes back the the original size?

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 Nomabond · Dec 14, 2014 at 04:26 PM 0
Share

You should run through these tutorials provided by Unity. They are exceptional and will help you jumpstart your UI development!

Unity UI Tutorials

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kiwasi · Dec 15, 2014 at 07:13 AM

If you use the UI you can fully animate your transitions. This allows whatever effect you want for mouse down.

Comment
Add comment · 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
0

Answer by zharik86 · Dec 14, 2014 at 07:58 PM

If you use old GUI, than you need to create style for button. Also create two textures of one size (for example, 64x64), but the picture of the second texture will be a little less than the first as it is necessary for you. Further, in new style you add to the fields "Normal" and "Hover" the first texture, and in the field of "Active" the second texture. Also don't forget to specify your style in the button. I hope that it will help you.

Comment
Add comment · Show 2 · 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 shay4545 · Dec 15, 2014 at 01:28 AM 0
Share

How would I go about this if I'm using Screen.width and Screen.height in my rect?

avatar image zharik86 · Dec 15, 2014 at 06:52 AM 0
Share

@shay4545 What difference as you set Rect. So, I will try once again. There are two ways of the solution of your task.

The first - program. For this purpose you have to define, whether your button is press, to do it slightly less. But it is a bad method.

The second - graphic. You draw, for example in Photoshop, texture for the button of 64x64 in size. You save it by the name of NormalTex. Further, in Photpshop, you scale your texture (layer!), doing it slightly less. Also you save by the name of ActiveTex (size picture is 64x64). Further you create GUIStyle in Unity (Right Click On Assets-> Create GUIStyle). In new style you add to the fields "Normal" and "Hover" the NormalTex, and in the field of "Active" the ActiveTex. In program:

  public GUIStyle myStyle = null; //reference for your style for button
  void OnGUI() {
   //Add your style at button
   if (GUI.Button(new Rect(0, 0, 200, 100), "btn", myStyle)) {
    //Do something
   }
  }
avatar image
0

Answer by ookk47oo · Apr 08, 2019 at 07:54 AM

 using System;
 using UnityEngine;
 using UnityEngine.UI;
 
 namespace GameApp
 {
     [Serializable]
     class ScaleButton : Button
     {
         [SerializeField]
         private float ClickScale = 0.75f;
 
         public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData)
         {
             base.OnPointerDown(eventData);
             transform.localScale = transform.localScale * ClickScale;
         }
 
         public override void OnPointerUp(UnityEngine.EventSystems.PointerEventData eventData)
         {
             base.OnPointerUp(eventData);
             transform.localScale = Vector3.one;
         }
 
         void OnApplicationFocus(bool isFocus)
         {
             if (!isFocus)
             {
                 transform.localScale = Vector3.one;
             }
         }
     }
 }
Comment
Add comment · 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
0

Answer by C8H11N02 · Apr 11, 2019 at 12:18 PM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Buttons : MonoBehaviour {
 
     void OnMouseDown () {
         transform.localScale = new Vector3(0.97f, 0.97f, 0.97f);
     } 
 
     void OnMouseUp () {
         transform.localScale = new Vector3(1f, 1f, 1f);
     }
 }

Comment
Add comment · 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

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

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

Related Questions

GUI.Button not showing up 1 Answer

GUI.Toolbar - Custom on/off button states 2 Answers

Create a Button Scrollview 0 Answers

How to create a gui button inside an if statement? 1 Answer

How to control keyboard via GUI button. 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