Why is this Raycast not casting a ray?
I have the ray casting in a project that has nothing but it won't even get to the Casted ray debug line.
Weird thing is it actually did work like once out of a thousand clicks.
Here is the code that was working in another project but ever since I've tried to move it no rays are being cast.
void FixedUpdate(){
MouseClickedTarget ();
}
void MouseClickedTarget ()
{
//Input.GetMouseButtonDown
if (Input.GetMouseButton(0))
{
Ray ray = new Ray(Camera.main.ScreenToWorldPoint( Input.mousePosition), Camera.main.transform.forward);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100))
{
Debug.Log("Casted ray");
if(hit.collider)
{
if(hit.collider.gameObject.tag == "target")
{
}
}
}//if(Physics.Raycast(ray, out hit, 100))
else
{
Debug.Log("No ray cast!");
}
}
}//void MouseClickedTarget ()
Answer by OncaLupe · Nov 13, 2015 at 08:22 PM
Physics.Raycast()
only returns true if it actually hit something. False means it hit nothing.
Answer by SKULLKRUSHER · Nov 14, 2015 at 10:17 AM
I think I had my box collider set to a number that was to small case I raised it to three on each axis and it now works.
Your answer
Follow this Question
Related Questions
adding range onto 2d raycast 3 Answers
Line of Sight and Raycasting 0 Answers
UI panel without Image component as Raycast target? It is possible? 5 Answers
Activate Button only by looking at it? 0 Answers