Guest User

Untitled

a guest
Jan 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. public static class My2DExtensions {
  2. public static bool IsLeftOf(this GameObject t1, GameObject t2)
  3. {
  4. if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; })
  5. }
  6. public static bool IsRightOf(this GameObject t1, GameObject t2)
  7. {
  8. if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; }
  9. }
  10. public static bool IsCenterOf(this GameObject t1, GameObject t2, float wiggleRoom=0f)
  11. {
  12. if(t1.transform.position.Distance(new Vector2(t2.transform.position.x, t1.transform.position.y))<=wiggleRoom) return true; else return false;
  13. }
  14. public static bool IsAbove(this GameObject t1, GameObject t2)
  15. {
  16. if(t1.transform.position.y > t2.transform.position.y){ return true; } else { return false; }
  17. }
  18. public static bool IsBelow(this GameObject t1, GameObject t2)
  19. {
  20. if(t1.transform.position.y < t2.transform.position.y){ return true; } else { return false; }
  21. }
  22. public static bool IsMiddleOf(this GameObject t1, GameObject t2, float wiggleRoom=0f)
  23. {
  24. if(t1.transform.position.Distance(new Vector2(t1.transform.position.x, t2.transform.position.y))<=wiggleRoom) return true; else return false;
  25. }
  26. }
  27.  
  28.  
  29. /* Usage in another script:
  30. if(thing1.IsLeftOf(thing2)) Debug.Log("It's to the left");
  31. if(thing1.IsAbove(thing2)) Debug.Log("It's above");
  32. if(thing1.IsCenterOf(thing2, 0.5f)) Debug.Log("It's centered within 0.5f horizontal distance");
  33. if(thing1.IsMiddleOf(thing2, 0.5f)) Debug.Log("It's centered within 0.5f vertical distance");
  34. */
Add Comment
Please, Sign In to add comment