- Home /
Question by
Bokaii · Sep 19, 2014 at 06:13 AM ·
gameobjectmultiplayerfpsraycastall
RaycastAll Detect if nothing hit
How do I check if my RaycastAll didn't hit anything?
Code:
RaycastHit[] hits;
hits = Physics.RaycastAll (transform.FindChild("Main Camera").position, transform.FindChild("Main Camera").forward);
float minDist;
minDist = Mathf.Infinity;
for(int i=0;i<hits.Length;i++){
if(hits[i].transform != this.transform){
if(Vector3.Distance(transform.FindChild("Main Camera").position, hits[i].point)<minDist){
minDist = Vector3.Distance(transform.FindChild("Main Camera").position, hits[i].point);
print ("We hit: " + hits[i].collider.name);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Check if RaycastAll hits[i].point == null 0 Answers
[CLOSED]RaycastAll Help 1 Answer
Bullet Effect (RaycastAll Question) 1 Answer
Closest array element 1 Answer
Add one on local z axis 3 Answers