Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HighlightIfVisible : MonoBehaviour {
  6.  
  7. public Color visible;
  8. public Color invisible;
  9.  
  10. // Use this for initialization
  11. void Start () {
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update () {
  17. Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
  18. Bounds bounds = gameObject.GetComponent<Renderer>().bounds;
  19. Material mat = gameObject.GetComponent<Renderer>().material;
  20. if (GeometryUtility.TestPlanesAABB(planes, bounds)){
  21. // Je suis potentiellement visible
  22. mat.color = visible;
  23. } else {
  24. // C'est sûr, je ne suis pas visible
  25. mat.color = invisible;
  26. transform.rotation = Random.rotation;
  27. }
  28. gameObject.GetComponent<Renderer>().material = mat;
  29. }
  30. }
Add Comment
Please, Sign In to add comment