gimm-platformer-project/Assets/Scripts/GroundCheck.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2021-10-31 13:43:04 -06:00
using UnityEngine;
2021-09-24 00:34:18 -06:00
public class GroundCheck : MonoBehaviour
{
2022-10-07 14:54:24 -06:00
GameObject player;
private LayerMask solidLayer;
2021-09-24 00:34:18 -06:00
private void Start()
{
2022-10-07 14:54:24 -06:00
player = gameObject.transform.parent.gameObject;
solidLayer = LayerMask.GetMask("SolidObject");
2021-09-24 00:34:18 -06:00
}
private void OnCollisionEnter2D(Collision2D collision)
{
2022-10-07 13:18:54 -06:00
if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino"))
2021-09-24 00:34:18 -06:00
{
2022-10-08 21:00:31 -06:00
//Debug.Log("Now standing on "+ collision.collider.name);
2022-10-07 14:54:24 -06:00
player.GetComponent<Movement2D>().isGrounded = true;
2021-09-24 00:34:18 -06:00
}
}
private void OnCollisionExit2D(Collision2D collision)
{
2022-10-07 13:18:54 -06:00
if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino"))
2021-09-24 00:34:18 -06:00
{
if (GetComponent<BoxCollider2D>().IsTouchingLayers(solidLayer) == false)
{
2022-10-08 21:00:31 -06:00
//Debug.Log("No longer standing on " + collision.collider.name);
2022-10-07 14:54:24 -06:00
player.GetComponent<Movement2D>().isGrounded = false;
}
2021-09-24 00:34:18 -06:00
}
}
}