Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Collision : MonoBehaviour
- {
- [Header("Layers")]
- public LayerMask groundLayer;
- [Space]
- public bool onGround;
- public bool onWall;
- public bool onRightWall;
- public bool onLeftWall;
- public int wallSide;
- [Space]
- [Header("Collisions")]
- public float collisionRadius = 0.25f;
- public Vector2 bottomOffset, rightOffset, leftOffset;
- private Color debugCollisionColor = Color.green;
- void Update()
- {
- onGround = Physics2D.OverlapCircle((Vector2)transform.position + bottomOffset, collisionRadius, groundLayer);
- onWall = Physics2D.OverlapCircle((Vector2)transform.position + rightOffset, collisionRadius, groundLayer)
- || Physics2D.OverlapCircle((Vector2)transform.position + leftOffset, collisionRadius, groundLayer);
- onRightWall = Physics2D.OverlapCircle((Vector2)transform.position + rightOffset, collisionRadius, groundLayer);
- onLeftWall = Physics2D.OverlapCircle((Vector2)transform.position + leftOffset, collisionRadius, groundLayer);
- wallSide = onRightWall ? -1 : 1;
- }
- private void OnDrawGizmos()
- {
- Gizmos.color = debugCollisionColor;
- var positions = new Vector2[] { bottomOffset, leftOffset, rightOffset };
- Gizmos.DrawWireSphere((Vector2)transform.position + bottomOffset, collisionRadius);
- Gizmos.DrawWireSphere((Vector2)transform.position + leftOffset, collisionRadius);
- Gizmos.DrawWireSphere((Vector2)transform.position + rightOffset, collisionRadius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement