Created
          January 17, 2019 21:46 
        
      - 
      
- 
        Save DataGreed/5e46a02bad70352d646d2fef5d73f525 to your computer and use it in GitHub Desktop. 
    An extension class for Unity Renderer that checks if it's seen from a specified camera
  
        
  
    
      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
    
  
  
    
  | using UnityEngine; | |
| public static class RendererExtensions | |
| { | |
| /// <summary> | |
| /// Checks if the object is visible from a certain camera | |
| /// </summary> | |
| /// <returns><c>true</c>, if visible, <c>false</c> otherwise.</returns> | |
| /// <param name="renderer">Object Renderer</param> | |
| /// <param name="camera">Camera</param> | |
| public static bool IsVisibleFrom(this Renderer renderer, Camera camera) | |
| { | |
| Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera); | |
| return GeometryUtility.TestPlanesAABB(planes, renderer.bounds); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment