- Home /
This post has been wikified, any user with enough reputation can edit it.
UnityEngine.Touch error
I have this script that is suppose to handle mobile touch input I found on forum but I keep getting the error message
error CS0030: Cannot convert type UnityEngine.Touch' to
Touch'
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TouchInput : MonoBehaviour {
public LayerMask TouchInputMask;
private List<GameObject> touchList = new List<GameObject>();
private GameObject[] touchesOld;
public RaycastHit hit;
void Update () {
if (Input.touchCount > 0){
touchesOld = new GameObject[touchList.Count];
touchList.CopyTo(touchesOld);
touchList.Clear();
foreach (Touch touch in Input.touches) { //This is where the error is coming from.
Ray ray = camera.ScreenPointToRay(touch.position);
RaycastHit hit;
if(Physics.Raycast(ray,out hit,TouchInputMask)){
GameObject recipient = hit.transform.gameobject;
touchList.add(recipient);
if(touch.phase == TouchPhase.Began){
recipient.SendMessage("OnTouchDown",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Ended){
recipient.SendMessage("OnTouchUp",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Stationary){
recipient.SendMessage("OnTouchStay",hit.point,SendMessageOptions.DontRequireReceiver);
}
if(touch.phase == TouchPhase.Canceled){
recipient.SendMessage("OnTouchExit",hit.point,SendMessageOptions.DontRequireReceiver);
}
}
}
foreach (GameObject g in touchesOld){
if (!touchList.Contains(g)){
g.SendMessage("OnTouchExit",hit.point,SendMessageOptions.DontRequireReceiver);
}
}
}
}
}
Comment
Best Answer
Answer by 767_2 · Sep 27, 2014 at 07:48 AM
try this
foreach (UnityEngine.Touch touch in Input.touches)