Eonirr

Untitled

Jan 16th, 2026
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public Vector2 boxSize;
  2. public Vector2 boxOffset;
  3. publicLayerMask groundLayer;
  4.  
  5. bool IsGrounded;
  6.  
  7. void Update()
  8. {
  9. CheckGround();
  10. }
  11.  
  12. void CheckGround()
  13. {
  14. Vector2 boxCenter = (Vector2)transform.position + boxOffset;
  15.  
  16. IsGrounded = Physics2D.OverlapBox(boxCenter, boxSize, 0f, groundLayer);
  17. }
  18.  
  19. void OnDrawGizmosSelected()
  20. {
  21. Gizmos.color = IsGrounded ? Color.green : Color.red;
  22.  
  23. Vector2 boxCenter = (Vector2)transform.position + boxOffset;
  24. Gizmos.DrawWireCube(boxCenter, boxSize);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment