Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //size of bullet
- public Vector2 bulletSize;
- //position of bullet
- public Vector2 bulletPos;
- //offset the colliders position by an amount
- public Vector2 colliderOffset;
- //what layers you want your collider to check with
- public LayerMask hitLayers;
- void Update () {
- //gets the position of the bullet and adds the offset
- bulletPos = gameObject.transform.position + colliderOffset;
- //checks if any objects under a box and puts them all in a collider array named hitZone
- Collider2D[] hitZone = Physics2D.OverlapBoxAll(bulletPos, bulletSize, 0, hitLayers);
- //for each item in the hitZone array it will run the fullowing script
- foreach (Collider2D collider in hitZone)
- {
- //compares the collider's gameobject's layer to what you set it as (replace with your specific layer)
- if (collider.gameObject.layer == >>>ReplaceThis<<<)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement