How to get touch input in unity | Sololearn: Learn to code for FREE!

+1

How to get touch input in unity

Hi guys i am using unity to developing games but i cant figure out how to get touch input in my games please help somebody please

12/31/2016 9:54:37 AM

Preetesh Shirkar

3 Answers

New Answer

+1

you can use the Input class eg: using UnityEngine; using System.Collections; public class ClassName :MonoBehaviour { int touches=Input.touchCount; void Update () { if (touches >0) { for (int I =0; i <touches; i++) { Touch t = Input.GetTouch (i); if (t.phase == TouchPhase.Began) { Ray Ray = Camera.main.ScreenPointToRay (t.position ); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // insert your code here // you can also check the object clicked by // doing the following. if (hit.transform.tag == "tag") { //do something } } } } } } }

+1

Thanks for answer

0