+ 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

31st Dec 2016, 9:54 AM
Preetesh Shirkar
Preetesh Shirkar - avatar
3 ответов
+ 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 } } } } } } }
1st Jan 2017, 12:11 AM
Pascal Benstrong
Pascal Benstrong - avatar
+ 1
Thanks for answer
1st Jan 2017, 6:03 AM
Preetesh Shirkar
Preetesh Shirkar - avatar
0
Hi
20th May 2017, 11:07 AM
Preetesh Shirkar
Preetesh Shirkar - avatar