void Update() { MouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { Collider2D collider = Physics2D.OverlapPoint(MouseWorldPosition); GlobalDownAction(MouseWorldPosition); if (collider != null) { Clickable clickable = collider.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.Down, MouseWorldPosition); } } else { Clickable clickable = Camera.main.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.Down, MouseWorldPosition); } } } else if (Input.GetMouseButtonUp(0)) { Collider2D collider = Physics2D.OverlapPoint(MouseWorldPosition); GlobalUpAction(MouseWorldPosition); if (collider != null) { Clickable clickable = collider.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.Up, MouseWorldPosition); } } else { Clickable clickable = Camera.main.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.Up, MouseWorldPosition); } } } else if (Input.GetMouseButtonDown(1)) { Collider2D collider = Physics2D.OverlapPoint(MouseWorldPosition); GlobalRightDownAction(MouseWorldPosition); if (collider != null) { Clickable clickable = collider.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.RightDown, MouseWorldPosition); } } else { Clickable clickable = Camera.main.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.RightDown, MouseWorldPosition); } } } else if (Input.GetMouseButtonUp(1)) { Collider2D collider = Physics2D.OverlapPoint(MouseWorldPosition); GlobalRightUpAction(MouseWorldPosition); if (collider != null) { Clickable clickable = collider.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.RightUp, MouseWorldPosition); } } else { Clickable clickable = Camera.main.GetComponent <Clickable>(); if (clickable != null) { clickable.FireEvent(MouseEventType.RightUp, MouseWorldPosition); } } } }