-
-
Save ViktorKrepelka/2a289878b4fec4deb8fc8cb3a77f1f3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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