Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
Dismiss Notice
Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.

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:
    34
    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.