Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Created July 16, 2016 16:12
Show Gist options
  • Select an option

  • Save timsgardner/b49dbf6010f618c8ee65019325f9669c to your computer and use it in GitHub Desktop.

Select an option

Save timsgardner/b49dbf6010f618c8ee65019325f9669c to your computer and use it in GitHub Desktop.
raycast helper
using UnityEngine;
using System.Collections;
public class RayCastHelper {
public static RaycastHit[] raycast(Ray ray) {
RaycastHit[] hits = new RaycastHit[0];
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
hits = new RaycastHit[1];
hits[0] = hit;
}
return hits;
}
public static float[] raycastPlane(Plane plane, Ray ray){
float[] outgoing;
float dist = 0;
if (plane.Raycast(ray, out dist)){
outgoing = new float[1];
outgoing[0] = dist;
} else{
outgoing = new float[0];
}
return outgoing;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment