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

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.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
{
Debug.Log("Now standing on "+ collision.collider.name);
Player.GetComponent<Movement2D>().isGrounded = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.collider.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
{
if (GetComponent<BoxCollider2D>().IsTouchingLayers(solidLayer) == false)
{
Debug.Log("No longer standing on " + collision.collider.name);
Player.GetComponent<Movement2D>().isGrounded = false;
}
}
}
}