Answer the question
In order to leave comments, you need to log in
How to fix ground touch check?
I'm making a 2d platformer. I made such a system for checking for touching the ground:
public class GroundChecker : MonoBehaviour {
private Character player;
private void Start()
{
player = GetComponentInParent<Character>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if ( collision.gameObject.layer==8)//8 слой-слой с объектами по которым можно ходить
{
player.onGround = true;
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.gameObject.layer == 8)
{
player.onGround = true;
}
}
//Проблемный участок//
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.layer==8)
{
player.onGround = false;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question