Skip to content

Instantly share code, notes, and snippets.

@DataGreed
Created January 17, 2019 21:46
Show Gist options
  • Save DataGreed/5e46a02bad70352d646d2fef5d73f525 to your computer and use it in GitHub Desktop.
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
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