- Home /
Question by
MichaelBoguslaw · Apr 03, 2015 at 05:17 AM ·
raycastmobilerays
OnMouseDown() ios subsitute not function correctly
For some reason, the Y origin of the ray is about 10 units higher than it should be when I tap the screen.
The screen size matches the device I'm testing with and also the cameras Y position is 0.
#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ConvertToTouch : MonoBehaviour
{
void Update ()
{
// Code for OnMouseDown in the iPhone
RaycastHit hit = new RaycastHit();
for (int i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
Debug.Log (ray);
if (Physics.Raycast(ray, out hit))
{
hit.transform.gameObject.SendMessage("OnMouseDown");
}
}
}
}
}
#endif
Comment