Hi to everybody…
I’ve little problem… I’ve implement this script for detect the name of object that i’ve touch:
using UnityEngine;
using System.Collections;
public class DetectTouch : MonoBehaviour {
private Ray touchRay;
private RaycastHit touchHit;
private GUIText messages;
private GameObject oggetto;
private Camera inputCamera;
void Awake(){
if(!inputCamera){
inputCamera = Camera.main;
oggetto = GameObject.Find("GUITesto");
messages = (GUIText) oggetto.GetComponent("GUIText");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
UpdateTouchInput();
}
void UpdateTouchInput(){
if(Input.touchCount == 1){
Touch touch = Input.touches[0];
if(touch.phase == TouchPhase.Began){
touchRay = inputCamera.ScreenPointToRay(touch.position);
if(Physics.Raycast(touchRay,out touchHit)){
switch(touchHit.collider.name){
default:
messages.text = touchHit.collider.name;
break;
}
}
}
}
}
}
it’s correctly function.
In another project i’ve use the prefab “TapToMove Controls” but when i touch the sphere for example, the script is not function… why???
Ps. This script is associate to the sphere…
Please help me…![]()