Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Scale A Unity Button When Clicked?

Discussion in 'Scripting' started by JeZxLee, Oct 6, 2016.

  1. JeZxLee

    JeZxLee

    Joined:
    Jul 24, 2016
    Posts:
    222
    Hi,

    So we are working on title screen interface now.
    We have a [START!] Unity button on the screen.
    How would we scale the button (make smaller then go back to default) when clicked?
    Thanks!
     
  2. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    We are going to need significantly more information in order to be able to help you... Are you using the old GUI system or the new one?
     
  3. JeZxLee

    JeZxLee

    Joined:
    Jul 24, 2016
    Posts:
    222
    Hi,

    Using the current non-beta version of Unity.
    Added a Unity button to scene by doing the following:
    GameObject->UI->Button

    Thanks!
     
  4. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    Last edited: Oct 6, 2016
  5. JeZxLee

    JeZxLee

    Joined:
    Jul 24, 2016
    Posts:
    222
    Hi,

    So we have a button we wish to scale down then up when clicked.
    We have created "controllers" assets including "Pressed" which we created/attached a C# script to.

    Little confused at this point, it created the following C# script code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ButtonSTARTScript : StateMachineBehaviour {
    5.  
    6.      // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    7.     //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    8.     //
    9.     //}
    10.  
    11.     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    12.     //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    13.     //
    14.     //}
    15.  
    16.     // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    17.     //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    18.     //
    19.     //}
    20.  
    21.     // OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
    22.     //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    23.     //
    24.     //}
    25.  
    26.     // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
    27.     //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    28.     //
    29.     //}
    30. }
    31.  
    Not sure how to proceed.
    On click of button we want it to scale down to 75% and then scale back up to 100%.
    Currently the Unity button is called: "ButtonSTART".

    Any guidance would be appreciated, thanks!
     
  6. flaminghairball

    flaminghairball

    Joined:
    Jun 12, 2008
    Posts:
    868
    You should have a "Pressed" animation clip -- add keyframes to it that scale up the button and it should give you the desired effect.
     
  7. JeZxLee

    JeZxLee

    Joined:
    Jul 24, 2016
    Posts:
    222
  8. JeZxLee

    JeZxLee

    Joined:
    Jul 24, 2016
    Posts:
    222
    Hi,

    We figured it out - needed to add an "EventSystem" to the screne.
    Thanks!