There spawns enemies in my game, which u have to tap to kill. The problem is, when i test my game on my iphone by exporting it through xcode, i can’t tap them. When i click on them with my mouse, on my computer it works, and when i use the unity remote app, i can tap them. But not when i export it to my iPhone. Everything else works in my game, but i cant tap the enemies.
The script i use for is this:
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;
private RaycastHit hit;
// Update is called once per frame
void Update () {
#if UNITY_EDITOR
if(Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) {
touchesOld = new GameObject[touchList.Count];
touchList.CopyTo(touchesOld);
touchList.Clear();
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit,touchInputMask)) {
GameObject recipient = hit.transform.gameObject;
touchList.Add(recipient);
if(Input.GetMouseButtonDown(0)) {
recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
} if(Input.GetMouseButtonDown(0)) {
recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
} if(Input.GetMouseButtonUp(0)) {
recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
foreach (GameObject g in touchesOld) {
if(!touchList.Contains(g)) {
g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
}
#endif
}
}
And on my enemy i have a script saying:
void OnTouchDown () {
if(GameObject.Find("spawn_Controller").GetComponent<Spawn>().gameOver == false) {
health = health -1;
Instantiate(blood,gameObject.transform.position, Quaternion.identity);
audio.PlayOneShot(gunShot, 0.7F);
audio.PlayOneShot(bloodSplat, 0.7F);
}
}
Can someone tell what is wrong?