#UI
1 messages · Page 1 of 1 (latest)
let me send you a screenshot, 1 sec
alright, I'm sure we can figure this out
rect.Contains stays false probably due to "Input.mousePosition" having absolute screen values, and the rect coordinates are local values
So it's trying to check if (710, 320) is contained in (0, 0, 1, 1)
Oke so you want a side bar that when you hover your mouse over the side the 2 buttons show up
How would i use it then?
Yes
Let me quickly hop in unity and see if I can recreate the problem
Not sure if unity has tools to convert from screen to local position, but you can always write your own custom method to check boudaries
private void Update()
{
if (HoverRect.rect.Contains(Input.mousePosition))
{
if (open == false)
{
open = true;
LeanTween.cancel(ButtonsPanel);
LeanTween.moveLocal(ButtonsPanel.gameObject, ShowPos, TweenTime).setEaseInOutCubic();
}
}
else
{
if (open == true)
{
open = false;
LeanTween.cancel(ButtonsPanel);
LeanTween.moveLocal(ButtonsPanel.gameObject, HidePos, TweenTime).setEaseInOutCubic();
}
}
}
quickly post for reference
Better yet
Try this:
HoverRect.rect.Contains(Input.mousePosition - HoverRect.rect.transform.position)
I did see a couple posts online, including unity official website, using input.mouseposition with rect.contains. So I wonder why they use it there...
Aight, 1 sec
Not sure if you can do rect.position directly, but something like that
I did save HoverRect as the Rect Transform, so we dont need to acces it like that
YES! It works. It works PERFECLY now
Thanks you so much
Good (:
nice
Just to make sure, did you understand why it works?
Yea, i was just about to ask. Would you explain why you should - HoverRect.position with Input.mousePosition?
Sure
Yea, also thanks for your help aswell :)
As I said, the Input.mousePosition is getting the mouse position on the screen, and the contains method is trying to check for local coordinates
When you subtract the rectangle position from the mouse position, you're looking for the mouse position relative to the rect position
This is harder to explain than I expected :P
Oh, so then your looking at the mouse as in with the rectangle's local position?
Exactly
ahhh, i see. Thanks! I learned somthing new today :D
Glad to help (: