Scale A Unity Button When Clicked?

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!

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?

Hi,

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

Thanks!

There is a very good tutorial on how to do Unity3D 4.6 GUI animations here. You could probably also do it with a custom script that implements OnPointerEnter, OnPointerExit, and OnPointerDown.

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:

using UnityEngine;
using System.Collections;

public class ButtonSTARTScript : StateMachineBehaviour {

     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}

    // OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
    //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}

    // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
    //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}
}

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!

You should have a “Pressed” animation clip – add keyframes to it that scale up the button and it should give you the desired effect.

Hi,

We thought we had everything setup correctly, but when we run the game the button does not work?
You can see a screenshot of Unity button setup below:
http://16bitsoft.com/files/MPB/images/MPB-ButtonNotWorking.png

Thanks in advance for your help!

Hi,

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