Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HighlightIfVisible : MonoBehaviour {
- public Color visible;
- public Color invisible;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
- Bounds bounds = gameObject.GetComponent<Renderer>().bounds;
- Material mat = gameObject.GetComponent<Renderer>().material;
- if (GeometryUtility.TestPlanesAABB(planes, bounds)){
- // Je suis potentiellement visible
- mat.color = visible;
- } else {
- // C'est sûr, je ne suis pas visible
- mat.color = invisible;
- transform.rotation = Random.rotation;
- }
- gameObject.GetComponent<Renderer>().material = mat;
- }
- }
Add Comment
Please, Sign In to add comment