Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class My2DExtensions {
- public static bool IsLeftOf(this GameObject t1, GameObject t2)
- {
- if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; })
- }
- public static bool IsRightOf(this GameObject t1, GameObject t2)
- {
- if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; }
- }
- public static bool IsCenterOf(this GameObject t1, GameObject t2, float wiggleRoom=0f)
- {
- if(t1.transform.position.Distance(new Vector2(t2.transform.position.x, t1.transform.position.y))<=wiggleRoom) return true; else return false;
- }
- public static bool IsAbove(this GameObject t1, GameObject t2)
- {
- if(t1.transform.position.y > t2.transform.position.y){ return true; } else { return false; }
- }
- public static bool IsBelow(this GameObject t1, GameObject t2)
- {
- if(t1.transform.position.y < t2.transform.position.y){ return true; } else { return false; }
- }
- public static bool IsMiddleOf(this GameObject t1, GameObject t2, float wiggleRoom=0f)
- {
- if(t1.transform.position.Distance(new Vector2(t1.transform.position.x, t2.transform.position.y))<=wiggleRoom) return true; else return false;
- }
- }
- /* Usage in another script:
- if(thing1.IsLeftOf(thing2)) Debug.Log("It's to the left");
- if(thing1.IsAbove(thing2)) Debug.Log("It's above");
- if(thing1.IsCenterOf(thing2, 0.5f)) Debug.Log("It's centered within 0.5f horizontal distance");
- if(thing1.IsMiddleOf(thing2, 0.5f)) Debug.Log("It's centered within 0.5f vertical distance");
- */
Add Comment
Please, Sign In to add comment