Search Unity

Question Animation not playing when Player enters a tilemap

Discussion in 'Animation' started by IgorArnaut, May 4, 2022.

  1. IgorArnaut

    IgorArnaut

    Joined:
    Nov 15, 2021
    Posts:
    36
    A Tilemap has a Tilemap Collider 2D and is set to be a trigger. A script in Tilemap has OnTriggerEnter2D method which sets bool value of Player's animation parameter. It should change Player's animation when enters that Tilemap.
    Code (CSharp):
    1.  
    2. private void OnTriggerEnter2D(Collider2D other)
    3. {
    4.     if (other.CompareTag("Player"))
    5.         other.gameObject.GetComponent<Animator().SetBool("inWater", true);
    6. }
    7.  
    Transitions between states have inWater parameter. In transition from Idle to Swim that parameter is true and is false in transition from Swim to Idle.

    When playing the game, inWater parameter doesn't change when Player enters that Tilemap and nothing happens. I don't know what's going wrong here.