- Home /
check touch position
hi i'm new to unity and i want to know how can i check if player touch the top right corner
for (var i = 0; i < Input.touchCount; ++i) { Touch touch = Input.GetTouch(i); if (touch.phase == TouchPhase.Began) if (/"touch is in top right corner/") return; }
Answer by Anis1808 · Dec 03, 2019 at 01:43 PM
I defined the top corner as 1/5th of the screen width and any value after 4/5 of the screen height but you can edit these values of course. The code is in general self-explanatory, you get the position of your touch, then you compare it with a position on the screen such as 1/5 of the screensize so it gives you your desired location.
Good Luck.
for (var i = 0; i < Input.touchCount; ++i) {
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began) {
if (touch.position.x > 4*Screen.width/5 && touch.position.y < Screen.height/5 ) {
return;
}
}
}
By the way, I would have looked on the internet first before posting, there a multiple answers available for this question look at https://answers.unity.com/questions/1238190/get-position-of-touch.html or the documentation
thanks,i seached on the internet for a week now but i thought that it had an easier way.and more precise.thanks again for your help.and i guess i have to work on my searching skills.
Your answer
Follow this Question
Related Questions
Unity Touch Help! 0 Answers
two finger touch always detects one finger touch first 1 Answer
A touch'es state is always Began and the position doesn't change 1 Answer
How to show and hide an image by swiping 0 Answers
Working with screen's touch limit 0 Answers