I want to perform some action when ever I tap on a 3d model object How to detect this? In Unity we have method OnMouseDown(). Any thing in Unity-iPhone like this?
Look up “iPhoneTouch” (or just Touch if you’re using Unity 3) in the Scripting documentation.
The big difference with Touch is that there are no labelled keys (or mouse buttons). You get a bunch of touches and need to figure out how to interpret them. It’s very flexible and powerful but significantly different from simply handling fixed event types.
E.g. the iPhone (or Unity iPhone, at least) won’t tell you that the user is performing a two-fingered pinch. You need to figure that out for yourself.
Thanks for the reply Podperson.
I got the solution by using raycast, here is the code
for (var touch : iPhoneTouch in iPhoneInput.touches) {
if (touch.phase == iPhoneTouchPhase.Began) {
// Construct a ray from the current touch coordinates
var ray: Ray = Camera.main.ScreenPointToRay (touch.position);
var hit: RaycastHit;
if (Physics.Raycast (ray,hit,1000)) {
hit.collider.gameObject.SendMessage("OnTouch");
}
}
}