UI-Triggered Animations
Animate UI Panels, Configure UI-Button Action Listeners
Last updated
Animate UI Panels, Configure UI-Button Action Listeners
Last updated
In this example, we have a BookPanel that allows the user to select buttons in the menu to view different text-sections. We also want this panel to be hidden. The tab-key animates the visibility with a slide-in from the left-side canvas border.
Step 1: Create A UI Panel with desired configuration
To create an animated UI element, such as a menu, etc. You will want all components nested as children within a top-level UI container such as a UI-panel. Animation scripts will be attached to this top-level panel - the 'BookPanel' in the example above.
Given a UI Panel such as the one listed above:
With the top-level panel selected in the inspector, open the animator window and you are prompted to 'To begin animating BookPanel, create an Animator and an Animation Clip': Select the 'Create' button and save as 'BookPanel_Visible' animation
Animator Component - Add Bool Parameter using the left side 'Parameters' tab as shown below.
Rect Transform - Position - As shown below - When Selecting the 'Add Property' Button, select the Rect-Transform: Anchored Position using the '+' symbol at the right side of the menu
Set the Anchored Position.x to have a value that makes the panel visible within the camera viewport. - Remove other Keyframes - only 1 keyframe time-point is required for each animation clip.
Selecting 'Create New Clip...'
Set the Anchored Position.x to have a value that makes the panel not visible within the camera viewport. - Remove other Keyframes - only 1 keyframe time-point is required for each animation clip.
Setup Animator Controller - Set BookPanel_InVisible as 'Layer Default State'
Change Book-Text with Button onClick:
Add this script to the Top-Level Panel - BookPanel