- Home /
Seeing if the player is currently touching a specific part of the screen.
Right now if I want to make stuff happen when the fire button is pressed I use:
if (Input.GetButton("Fire1"))
What do I need do to make stuff happen when the player touches a certain part of the screen? I can store Rect information to define that area, but then what?...
Answer by rutter · Apr 07, 2012 at 03:12 AM
Depending on your platform, you could use `Input.mousePosition` and/or the `position` property of each value in `Input.touches`. The script reference pages I've linked will provide you with more information about those values, but the short version is that they'll give you a screen coordinate in pixels.
You could check that against one or more rectangles.
Many people find `Camera.ScreenPointToRay()` useful, for using screen positions with `Physics.Raycast()`.
Your answer
Follow this Question
Related Questions
Two finger dragging/rotation of a sprite? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can I use OnMouseDown for touch input? C# Nexus 2 Answers
Problem with rect and touch 1 Answer