home, UNITY, updated

How to trigger transition animation in Unity?

You can make multiple animations in unity. Once you make the animation, open the Animator Controller, Now make a condition trigger, and named it "Start" or whatever you want. Then You need to call it anywhere in the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class LevelLoader : MonoBehaviour
{
    public Animator transition;
    public Image Circle;

    public void LoadLevel(){
        transition.ResetTrigger("Start");
        transition.SetTrigger("Start");
        StartCoroutine(changeScene());
        
    }
    IEnumerator changeScene(){
        yield return new WaitForSeconds(0.9f);
        if(Circle.color == Color.red)
         {
             Circle.color = Color.green;
         }else{
             Circle.color = Color.red;  
         }
    }


}
In this example, we change the color of a Sprite in the middle of the animation.

Related Articles

post a comment