Skip to content

Instantly share code, notes, and snippets.

@ViktorKrepelka
Created August 8, 2023 05:34
Show Gist options
  • Select an option

  • Save ViktorKrepelka/2a289878b4fec4deb8fc8cb3a77f1f3b to your computer and use it in GitHub Desktop.

Select an option

Save ViktorKrepelka/2a289878b4fec4deb8fc8cb3a77f1f3b to your computer and use it in GitHub Desktop.
//return closest face to user
public Transform getClosestFace(Transform[] child, Camera cam)
{
Transform closestFace;
try
{
closestFace = child[1];
}
catch (Exception)
{
closestFace = child[0];
}
foreach (Transform face in child)
{
if (face.childCount != 0)
{
continue;
}
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam);
float closestFaceDistance = GetVisiblePercentage(closestFace.GetComponent<MeshRenderer>().bounds, cam);
float faceDistance = GetVisiblePercentage(face.GetComponent<MeshRenderer>().bounds, cam);
if (faceDistance < closestFaceDistance)
{
closestFace = face;
}
}
return closestFace;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment