Triggerbox not registering OnTriggerEnter2d

Im sorry If the solution is a very simple Fix I’m completely new to Unity and coding.

To learn c# I am following a Tutorial but for a few hours I have been attempting to Fix an issue I have with a Trigger box not sending a signal. I am not sure if it is a Coding issue or something I didn’t link correctly or a bug.

To put in context I created a “player” this character has simple animation for when he is idle, walking, and Jumping. my current goal is to get the appropriate animation to play. To do this I created a Triggerbox attached to Player in the hierarchy. The “Is Trigger” box is ticked and a Code is attached to the box.

The code is to check for collision on the box, this will tell me if the “Player” is Grounded or not. I use OnTriggerEnter2d and Exit but when i press play it appears that the collision box is not triggering. The player is always in the Jump animation because “Grounded” is false even though the Player and the trigger box is touching the ground.

the Triggerbox Code:

using UnityEngine;
using System.Collections;

public class GroundCheck : MonoBehaviour {

	private Player player;
	
	void Start()
	{
		player = gameObject.GetComponentInParent<Player> ();
	}

	void OnTriggerEnter2d(Collider2D col)
	{
		player.grounded = true;
	}

	void OnTriggerExit2d(Collider2D col)
	{
		player.grounded = false;
	}
}

Im am complete lost any help would be appreciated.

  1. i don’t see Animator component in the script so you can enter the animator controller & play animations.

      Animator anim;
         void Start()
         	{
         		anim = GetComponent<Animator> ();
         	}
    
  2. if this script is attached to the player you don’t need :

            private Player player; 
         void Start()
         {
             player = gameObject.GetComponentInParent<Player> ();
         }
    
  3. in the OnTriggerEnter2d or Exit you have to test what you are colliding with :

    void OnTriggerEnter2d(Collider2D col)
         {
             if(col.gameObject.name == "Ground")
            //now you should enter the Animator & set a bool variable you already added to true or false so if the variable name in the Animator is Grounded :
    

    anim.SetBool(“Grounded”, true);
    }