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;
}
}
}
public class GroundChecker : MonoBehaviour {
private Character player;
private int newobjlayer;
private void Start()
{
player = GetComponentInParent<Character>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
//if (collision == null) print("abcd");
newobjlayer= collision.gameObject.layer;
if ( collision.gameObject.layer==8)
{
player.onGround = true;
//print(collision);
}
if (collision.gameObject.layer != 8)
{
player.onGround = false;
//print(collision);
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (collision.gameObject.layer == 8)
{
player.onGround = true;
//print(collision);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
Vector3 speed = player.GetComponent<Rigidbody2D>().velocity;
if (collision.gameObject.layer == 8 && speed.y<0||speed.y>0)
{
player.onGround = false;
}
}
}