Skip to content

Commit

Permalink
Find mouse coordinates even if there's a worldCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Jul 26, 2020
1 parent ddcbd1f commit 00c5ae7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Runtime/Navigation/VioletButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ void OnGUI() {
mousePosition.y = UnityEngine.Screen.height - mousePosition.y;

var rect = GetComponent<RectTransform>().rect;
var camera = GetComponentInParent<Canvas>().worldCamera;
if (camera != null) {
mousePosition = camera.ScreenToWorldPoint(mousePosition);
}
var topLeft = transform.position + new Vector3(rect.xMin, rect.yMin, 0);
var bottomRight = transform.position + new Vector3(rect.xMax, rect.yMax, 0);
if (topLeft.x <= mousePosition.x && mousePosition.x <= bottomRight.x &&
topLeft.y <= mousePosition.y && mousePosition.y <= bottomRight.y ) {
Submit();
} else {
Violet.LogVerbose($"topLeft={topLeft} bottomRight={bottomRight} mousePosition={mousePosition}");
Violet.LogVerbose($"transform.position={transform.position} topLeft={topLeft} bottomRight={bottomRight} mousePosition={mousePosition}");
}
}
#endif
Expand Down

0 comments on commit 00c5ae7

Please sign in to comment.