- Home /
GUI Texture overlap Click/Tap
Hey guys, I've run into a bit of a problem. I have a guitexture that takes up the entire screen and when clicked/tapped it starts the game. The only problem is that I have other gui textures on top that act as small buttons. When I click one of the gui textures on top of the large one, the click is registered on both gui textures - the large one behind and the small one. Is there a way I can fix this and make the click on the one that is closest in z space the only click without registering a click on the large one? Thanks!
Answer by ozdenselim · Oct 30, 2014 at 01:15 PM
Create a Rect variable that includes the small one's pixelInset values. (lets say sampleRect)
Then you can check whether the touch is on small one by a boolean as follows (bool isTouching;)
void Update()
{
foreach (Touch touch in Input.touches)
{
if (sampleRect.Contains (touch.position))
{
isTouching = true;
}
else
{
isTouching = false;
}
}
}
Then you can put an if statement for the large one's hitTest function.
if (isTouching == false)
{
//Hittest function here
}
So it starts working when the touch is not on small one.
I hope that works.
Your answer

Follow this Question
Related Questions
How to make unity expect a click 0 Answers
Incorrect button event positioning 0 Answers
UI - click through image 2 Answers
button click event question 1 Answer
Click Goes Everywhere 0 Answers