Hello,
I have a quad with a PNG inside as a child object.
The Quad covers the whole screen.
I want to detect if the user has tapped on the right half of the script or the left half.
I tried with several methods, no success.
How would you solve this?
Here is the Update function:
void Update () {
bool tapped = Input.GetButtonUp(“Fire1”);
if (tapped){
//somehow divide the widht of the quad by half and check the mouse / tap position? like
//if(mousePosition > quad.width / 2)
//since im new to unity, this is just pseudocode
}
}
1 Like
Hi mirzahat,
First of all i would like to tell you that welcome to unity3d gaming.For your problem you have to do the code below .
function Update () {
var rect = Rect (0, 0, 150, 150);
if (rect.Contains(Input.mousePosition))
print(“Inside”);
}
It will solve your problem. Basically rect is the area you have to define.You can define two rect to test the left and right portion of the screen.There are so many other ideas.But this is one of them…
Hope this would help you.
Thanks
Hi
thanks for the answer.
This looks like a simple and effective method.
I have found a different solution on my own so far and it works :-).
Your solutions is great for a different scenario in my game where I need to capture clicks / touches.
Mirza
1 Like
Just for future reference the coder/programmer guys around here prefer when code is added to a post using the insert button. Welcome both.
it looks like this when used
2 Likes