VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/ui-animation-in-animation/

⇱ UI Animation In Animation - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

UI Animation In Animation

Last Updated : 6 May, 2026

Buttons feel more responsive when they react to player interaction. A button that grows when hovered and pops when clicked feels alive. This article shows two ways to animate buttons – using Animator component and using simple code.

Effect 1: Small to Large using Animator

When the mouse hovers over the button, the button smoothly grows from small to large size. This is done using Unity's Animator component without writing any code.

Step 1: Select your Button in Hierarchy.

Step 2: Change Transition to Animation:

  • In the Inspector, find the Button component.
  • Click the Transition dropdown and change from "Color Tint" to "Animation".

Step 3: Auto-Generate Animations:

  • Click the "Auto-Generate Animation" button.
  • Unity automatically creates an Animator component and animation clips for Normal, Highlighted, Pressed and Disabled states.

Step 4: Edit the Highlighted State (Hover Effect):

  • Open Animation window (Window - Animation - Animation)
  • Click the "Highlighted" tab
  • Click "Add Property" - Transform - Scale
  • Set keyframes:
  • At time 0: Scale = (2, 2, 2) [small size]
  • At time 0.1: Scale = (2.7, 2.7, 2.7) [large size]

Output: When the mouse hovers on button, it grows from 80% to 120% size smoothly. When the mouse leaves, it returns to normal.

👁 Button-Animation-using-Animator-In-Unity
UI Animation Using Animator In Unity

Effect 2: Simple Effect using Code

Same scale effect but controlled by script.

Attach this script to any button. Mouse enter - button becomes 1.2x. Mouse exit - back to 1x.

Output:

👁 UI-Animation-Using-Code-In-Unity
UI Animation Using Code In Unity

Both Methods Compared

Animator Method

  • No coding required
  • Provides smooth animations
  • Moderate level of customization
  • Best when all buttons use the same effect

Code Method

  • Requires coding
  • Can achieve smooth animation (using coroutine)
  • Very easy to customize
  • Best when different buttons need different effects
Comment
Article Tags:
Article Tags:

Explore