Can't play and change the animator animations in unity

30 views Asked by At

i have cone and it has mesh collider, it is trigger, i have one animator with two animations, 1 st animation name is "Animation1" and the second animation name is "Animation2", in animator parameters i have boolean with name Playanimation and in transition condition is true. I want to change the condition to false to play second animation, when player touch the cone collider. And here is the script, that i attach to cone. But the script doesn't work, unity always plays the first animation1. I want to play animation2 in animator when player touch with clone collider and again animation 1 if player doesn't touch the collider.

using UnityEngine;

public class ConeColliderController : MonoBehaviour
{
    private Animator animator;

    private void Start()
    {
        // Get a reference to the Animator component on the object with your animations
        animator = GetComponentInParent<Animator>();
    }

    private void OnTriggerEnter(Collider other)
    {
        // Check if the colliding object is the player
        if (other.CompareTag("Player"))
        {
            // Change the condition to false in the Animator
            animator.SetBool("Playanimation", false);
        }
    }
}
0

There are 0 answers