33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
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<Movement2D>().isGrounded = true;
|
|
}
|
|
}
|
|
|
|
private void OnCollisionExit2D(Collision2D collision)
|
|
{
|
|
if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino"))
|
|
{
|
|
if (GetComponent<BoxCollider2D>().IsTouchingLayers(solidLayer) == false)
|
|
{
|
|
//Debug.Log("No longer standing on " + collision.collider.name);
|
|
player.GetComponent<Movement2D>().isGrounded = false;
|
|
}
|
|
}
|
|
}
|
|
}
|