- Home /
This question was
closed Sep 23, 2016 at 09:04 PM by
soydasmemet for the following reason:
Other
Question by
soydasmemet · Sep 23, 2016 at 04:28 PM ·
physicsraycasttouchraycastingphysics.raycast
Raycast does not work with touch input but works well with mouse input why?
Hello everyone,
I search but i can not find anything useful for my problem. Raycast doesn't work with touch input as i did at this code sample below.
if(!EventSystem.current.IsPointerOverGameObject())
{
for (int j = 0; j < Input.touchCount; j++)
{
if(Input.GetTouch(j).phase == TouchPhase.Began)
{
groundRay = Camera.main.ScreenPointToRay (Input.GetTouch(j).position);
if (Physics.Raycast (groundRay, Mathf.Infinity))
{
SendMessage ("OnFire");
}
}
}
}
But like this way with the mouse input it works well. What is wrong?
if(!EventSystem.current.IsPointerOverGameObject())
{
if(Input.GetMouseButtonDown(0))
{
groundRay = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (groundRay, Mathf.Infinity))
{
SendMessage ("OnFire");
}
}
}
Comment
Follow this Question
Related Questions
if ( Physics.Raycast ( ray, out hit, Mathf.Infinity, LayerMask ) ) not working? 2 Answers
Slant Physics Raycast Implementation 0 Answers
Raycast hit in OnDrawGizmos but not in Update 1 Answer
Why does my Physics.Raycast not hit my BoxCollider? 4 Answers
Raycasting UI elements - Without using Event Triggers 0 Answers