- Home /
Unity iPhone does not detect mouse clicks as taps
I am using Unity iPhone version 1.5.1f2. I am trying to detect taps on 3D objects using rays. On the simulator I am using mouseclicks as taps. However, Unity does not catch the mouseclicks. Here is the code I am using, adapted from code I found online:
using UnityEngine;
using System.Collections;
public class multitouch_response : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
public int tc = 0;
void Update () {
// Code for OnMouseDown in the iPhone. Unquote to test.
RaycastHit hit = new RaycastHit();
Debug.Log("touchCount " + iPhoneInput.touchCount + " taps " + tc);
for (int i = 0; i < iPhoneInput.touchCount; ++i) {
Debug.Log("Touches");
if (iPhoneInput.GetTouch(i).phase.Equals(iPhoneTouchPhase.Began)) {
Debug.Log("Touch began");
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(iPhoneInput.GetTouch(i).position);
if (Physics.Raycast(ray, out hit)) {
hit.transform.gameObject.SendMessage("OnMouseDown");
}
}
}
}
public void OnMouseDown () {
tc++;
}
}
The only debug information produced is:
touchCount 0 taps 0
So this means the code is not picking up any touches.
Can someone help explain what I'm doing wrong here?
Much appreciated, Eric
you might want to use the Input.Touches http://unity3d.com/support/documentation/ScriptReference/Input-touches.html ins$$anonymous$$d of the deprecated iPhoneInput http://unity3d.com/support/documentation/ScriptReference/Touch.html
@Ina: $$anonymous$$y unity version doesn't have mobile devices in Input. It's an old version, and right now I'm not keen on paying the upgrade cost to fix this one problem.
Answer by GoSuNeem · Oct 30, 2011 at 02:31 PM
I have not used a older version of unity so I can't give a definate answer but in current version, mouse events are turned off when you are on Iphone/iPad mode. If you really want to use mousedowns for testing, you should use input.GetMouseButtonDown(0) or input.GetButtonDown() in update.
http://unity3d.com/support/documentation/ScriptReference/Input.GetMouseButtonDown.html
@GoSuNeem: Thanks for the response. That makes sense. I had thought Unity would consider mouseclicks to be taps, but I guess not.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024628im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making a GUI Texture tappable on iPhone 4 Answers
Touch.deltaTime confusion 0 Answers
Help with code logic iPhone Touch FPS 0 Answers
Tapping an object in an Android game 0 Answers