Advertisement
Guest User

Reverse trigger

a guest
Mar 24th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1.     //size of bullet
  2.     public Vector2 bulletSize;
  3.     //position of bullet
  4.     public Vector2 bulletPos;
  5.     //offset the colliders position by an amount
  6.     public Vector2 colliderOffset;
  7.     //what layers you want your collider to check with
  8.     public LayerMask hitLayers;
  9.  
  10. void Update () {
  11.         //gets the position of the bullet and adds the offset
  12.         bulletPos = gameObject.transform.position + colliderOffset;
  13.         //checks if any objects under a box and puts them all in a collider array named hitZone
  14.         Collider2D[] hitZone = Physics2D.OverlapBoxAll(bulletPos, bulletSize, 0, hitLayers);
  15.         //for each item in the hitZone array it will run the fullowing script
  16.         foreach (Collider2D collider in hitZone)
  17.         {
  18.             //compares the collider's gameobject's layer to what you set it as (replace with your specific layer)
  19.             if (collider.gameObject.layer == >>>ReplaceThis<<<)
  20.             {
  21.  
  22.             }
  23.  
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement