- Home /
Question by
Bill Cousert · Nov 21, 2011 at 05:11 PM ·
raycastonmousedownonmouseup
Raycast examples needed - alternative to OnMouseDown, OnMouseUp
I'm looking for some examples or tutorials that show how to use raycast as a replacement for OnMouseDown and OnMouseUp in mobile apps.
Comment
Answer by aldonaletto · Nov 21, 2011 at 06:58 PM
You have some information and examples about touches in mobile devices in the Reference Manual. The code below is based on one of those examples, and fills a RaycastHit structure with information about the object touched:
function Update () { var touch = Input.GetTouch[0]; if (touch.phase == TouchPhase.Began) { // if touch started... // Construct a ray from the current touch coordinates var ray = Camera.main.ScreenPointToRay (touch.position); var hit: RaycastHit; if (Physics.Raycast (ray, hit)) { // hit contains information about the object clicked // like hit.transform etc. } } } }
Your answer
Follow this Question
Related Questions
Question about raycasts and OnMouse functions 0 Answers
OnMouseButtonDown raycast 2 Answers
OnMouseButtonDown Raycast multiple Objects 0 Answers
OnMouseDown for Right Mouse 2 Answers
How to: Click top Object of 2 overlapping objects (2D) 1 Answer