- Home /
Question by
xXPekoXx · Jul 07, 2014 at 08:33 AM ·
raycasting
Raycasting not working properly
Hi guys, I have an issue with Ray casting
I instantiate 5 moles. and i want them to be whackable so i can play. so i give them collider box and apply some kind of ray casting functions but the ray cast feature is just half working it just detect half of them only 2 out of 5 are detected before it was in 3d and that was working really great now i switch in 2d but still have 3d collider as you can see on the picture the red are detected the green one some time, and the 2 other in the back are completely ignored i triyed on OnMouseUp same result .:(
pls help :/
post.jpg
(272.5 kB)
Comment
here is the code btw
using UnityEngine; using System.Collections;
public class test : $$anonymous$$onoBehaviour {
void Update() {
if(Input.Get$$anonymous$$ouseButtonUp(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit) && hit.transform == transform)
{
Debug.DrawLine(ray.origin, hit.point);
print ("hit");
}
}
}
}
Your answer
