2021-09-24 00:34:18 -06:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class GroundCheck : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
GameObject Player;
|
2021-10-14 13:24:05 -06:00
|
|
|
|
private LayerMask solidLayer;
|
2021-09-24 00:34:18 -06:00
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
Player = gameObject.transform.parent.gameObject;
|
2021-10-14 13:24:05 -06:00
|
|
|
|
solidLayer = LayerMask.GetMask("SolidObject");
|
2021-09-24 00:34:18 -06:00
|
|
|
|
}
|
|
|
|
|
private void OnCollisionEnter2D(Collision2D collision)
|
|
|
|
|
{
|
2021-10-07 13:56:22 -06:00
|
|
|
|
if (collision.collider.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
|
2021-09-24 00:34:18 -06:00
|
|
|
|
{
|
2021-10-14 13:24:05 -06:00
|
|
|
|
Debug.Log("Now standing on "+ collision.collider.name);
|
2021-09-24 00:34:18 -06:00
|
|
|
|
Player.GetComponent<Movement2D>().isGrounded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCollisionExit2D(Collision2D collision)
|
|
|
|
|
{
|
2021-10-07 13:56:22 -06:00
|
|
|
|
if (collision.collider.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
|
2021-09-24 00:34:18 -06:00
|
|
|
|
{
|
2021-10-14 13:24:05 -06:00
|
|
|
|
if (GetComponent<BoxCollider2D>().IsTouchingLayers(solidLayer) == false)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("No longer standing on " + collision.collider.name);
|
|
|
|
|
Player.GetComponent<Movement2D>().isGrounded = false;
|
|
|
|
|
}
|
2021-09-24 00:34:18 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|