Hello All,
I encountered an error which I wasn’t able to solve, and not understand what the problem is.
I want to check if my mouse position is over a UI elements rect.transform, but even if it’s over, the rect.contains give me false result.
The code:
public bool OverGameSpeed(Vector2 coords)
{
return (gamespeedRT.rect.Contains(coords));
}
void Update()
{
Debug.Log("View button: " + viewButton);
Debug.Log("Rect: " + gamespeedRT.position.x + " " + gamespeedRT.position.y);
Debug.Log("RectSize: " + gamespeedRT.sizeDelta.x*gamespeedRT.localScale.x + " " + gamespeedRT.sizeDelta.y*gamespeedRT.localScale.y);
Debug.Log("Mousepos:" + MouseControl_.MouseWorldPoint().x + MouseControl_.MouseWorldPoint().y);
Debug.Log("Contain: " + OverGameSpeed(new Vector2(MouseControl_.MouseWorldPoint().x, MouseControl_.MouseWorldPoint().y)));
OverGameSpeed(new Vector2(MouseControl_.MouseWorldPoint().x, MouseControl_.MouseWorldPoint().y))
}
The mousecontrol converts the mouse position to World coordinates, it’s working because if you see the pictures the coordintes should be inside the rect transform.
Any advice? What am I missing?