From 00c5ae731ed4e4e7017250fd22d9cb93b902fafd Mon Sep 17 00:00:00 2001 From: Neil Sarkar Date: Sun, 26 Jul 2020 13:31:59 -0700 Subject: [PATCH] Find mouse coordinates even if there's a worldCamera --- Runtime/Navigation/VioletButton.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Runtime/Navigation/VioletButton.cs b/Runtime/Navigation/VioletButton.cs index be12a46..ef2af72 100644 --- a/Runtime/Navigation/VioletButton.cs +++ b/Runtime/Navigation/VioletButton.cs @@ -49,13 +49,17 @@ void OnGUI() { mousePosition.y = UnityEngine.Screen.height - mousePosition.y; var rect = GetComponent().rect; + var camera = GetComponentInParent().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