Search Unity

Question Help with play and change the animator animations

Discussion in 'Animation' started by armspecial, Sep 10, 2023.

  1. armspecial


    Oct 28, 2014
    Hi. 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 2023-09-10_09-12-20.jpg 2023-09-10_09-13-14.jpg 2023-09-10_09-13-39.jpg

    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);