private void FixedUpdate()
    {
        Debug.DrawRay(transform.position + detectOffset, Vector3.down * detectDepth, Color.yellow);
        var        originPoint = transform.position + detectOffset;
        RaycastHit hit;

        if (Physics.Raycast(originPoint, Vector3.down, out hit, detectDepth, detectMask.value))
        {
            if (!lastGround)
            {
                OnTouchGround?.Invoke(hit.collider);
            }

            lastGround = hit.collider;

            OnStayGround?.Invoke(hit.collider);
        }
        else
        {
            OnLeaveGround?.Invoke(lastGround);
            lastGround = null;
        }
    }
Пример #2
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     isGrounded = false;
     OnLeaveGround?.Invoke();
 }