- Home /
How to animate a UI Button without using Mecanim? (For example, by using DOTween instead)
I'd like to be able to animate my button upon different events like press, release etc. But I'd prefer not to use Mecanim and instead tween the buttons myself using DOTween. Is there a way I can do this?
               Comment
              
 
               
              Answer by Chanisco · Aug 11, 2017 at 07:40 PM
you need the Unity Pointhandlers:
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class *yourScriptName*: MonoBehaviour, IPointerEnterHandler ,IPointerExitHandler{
 
     // Mouse gets into UI-Box
     public void OnPointerEnter(PointerEventData data) {
         StartCoroutine(Animate(true));
     }
     //Mouse gets outside UI-Box
     public void OnPointerExit(PointerEventData data) {
         StartCoroutine(Animate(false));
     }
 
     private IEnumerator Animate(bool hover) {
         if (hover == true) {
             //Animate in
         }else {
             //Animate Out
         }
         yield break;
     }
     
 }
 
Your answer
 
 
             Follow this Question
Related Questions
How to change color of animated Text component 2 Answers
Make a button selectable for controller but not interactable 0 Answers
Unity UI Button states 1 Answer
Buttons become invisible when changing color (on Button or on Image) in script -1 Answers
Unity 5.0.2f1 UI Button OnClick Function 6 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                