For some reason I can’t figure out how to get OnCollisionEnter2D &Exit2D to work.I have attached a small hitbox to the bottom of my character in a child but it seems to not be able to check when it hits the ground and when it exits. It stays in one state and when you hit a corner it goes berzerk. My main aim is for it to not be able to double or triple jump. I have the parent script check if the variable isGrounded is true or false and jump accordingly.The parent script is called Move2D if you need it.
Any help would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grounded : MonoBehaviour
{
GameObject Player;
// Start is called before the first frame update
void Start()
{
Player = gameObject.transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D(Collision2D Collision){
if(Collision.collider.name == "Ground_1"){
Debug.Log("Hit with ground");
Player.GetComponent<Move2D>().isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D Collision){
if(Collision.collider.name == "Ground_1"){
Debug.Log("Left the ground");
Player.GetComponent<Move2D>().isGrounded=false;
}
}
}