OnTriggerEnter animation question

Hello there. I started to learn unity about 1 week ago. I’ve done my player controller with animation, so it works clearly.


Now I want to add boss animation when the player touches the Trigger. But it doesnt work. The boss (robot) is flipping (its work correctly) but his animation (SunJacking) doesn’t play. I’ve done the transition between “Any State” and “SunJacking”. The bool parameter has been done too (came). I’ve tried to use “SetBool” and “anim.Play” too. So here is my code. Hope you will help me with my learning x).


Best wishes, Awaking

using UnityEngine;

public class SunChap1 : MonoBehaviour
{
    public GameObject player;
    public GameObject robot;
    private Animator anim;
    private Animation an1;
    void Start()
    {
        anim = GetComponent<Animator>();
        an1 = GetComponent<Animation>();
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            Flip(robot);
            //            anim.SetBool("Came", true);                       //my first try
            //            anim.Play("SunJacking");                              //my second try 
            
        }
    }
    void Flip(GameObject robot)
    {
           Vector2 theScale = transform.localScale;
           theScale.x = 1;
           robot.transform.localScale = theScale;
    }
}

your code and animator window seems fine. dude I have a question,If you click on the Came bool in the animator window,then Sunjacking animation will play?

because you’re using OnTriggerEnter2D ,it means that at least one of your objects should has a rigidbody2D and they both should have boxCollider2D component and at least one of them should has a trigger boxCollider2D .please check this.