using UnityEngine; public class GroundCheck : MonoBehaviour { GameObject player; private LayerMask solidLayer; private void Start() { player = gameObject.transform.parent.gameObject; solidLayer = LayerMask.GetMask("SolidObject"); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino")) { Debug.Log("Now standing on "+ collision.collider.name); player.GetComponent().isGrounded = true; } } private void OnCollisionExit2D(Collision2D collision) { if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino")) { if (GetComponent().IsTouchingLayers(solidLayer) == false) { Debug.Log("No longer standing on " + collision.collider.name); player.GetComponent().isGrounded = false; } } } }