how can i get the Rect of the elements on GUI and use them?,how to get the position of GUI elements on screen to use it in code?
Hi all. I'm testing with a game, and wrote the code bellow to make the camera rotate when you swipe on the screen. but one problem is that when you swipe the "crossPlatformInputs" in unity standard prefabs, that i used to make the player move, the camera rotates with it. I found a solution on the net and added it to my code in "InputOverGUI" class, but i don't know how to get the guiRects and give it to the class. Now how can i get the positions of Inputs (multiple)? And do you think its a good way to achieve my goal?
void Update()
{
Touch[] touch = Input.touches;
if (touch[0].phase == TouchPhase.Moved && InputOverGUI(????))
{
delta = touch[0].deltaPosition;
}
else delta = new Vector2(0,0);
}
private bool InputOverGUI (Rect[] guiRects)
{
inputPos = new Vector2[Input.touchCount];
for (int i = 0; i<Input.touchCount; i++)
{
inputPos[i] = Input.touches[i].position;
}
foreach (Vector2 v in inputPos)
{
foreach (Rect rect in guiRects)
{
if (rect.Contains(v)) return false;
}
}
return true;
}
Your answer
Follow this Question
Related Questions
Detect how long a tap is held 1 Answer
Pinch to zoom camera: trembling when at minimum zoom 0 Answers
Touch doesen´t work on Unity Remote, why? 0 Answers
Unity / Oculus - Touch object as trigger 0 Answers
Cant get Touch Position.x 0 Answers