How do I tell when an object leave the visible area of my scene?

Hi,

I'm trying to tell when the player leave the ara visible on screen. I have the following attached to the player's `GameObject` but the `OnBecameInvisible` method never gets called. I'm guessing it has to do with shadows or something that keeping it marked as "visible". Is there any way to tell if its on screen regardless of shadows, other cameras, etc.?

Thanks,

using UnityEngine;
using System.Collections;

public class ShipOrbitPlanet : MonoBehaviour {
    private int mode = 0;

    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
    }

    void OnTriggerEnter(Collider Obj) {
        if (Obj.gameObject.tag == "Planet" && mode == 0) {
            Debug.Log("Entering Orbit");
            SystemController.instance.SetFocus(Obj.gameObject);
            transform.localScale /= 20;
            mode = 1;
        }
    }

    void OnBecameInvisible() {
        if (mode == 1) {
            Debug.Log("Leaving Orbit");
            SystemController.instance.SetFocus(null);
            transform.localScale *= 20;
            mode = 0;
        }
    }
}

Update

I think the issue is the object the script is attached to doesn't have a renderer.

MissingComponentException: There is no 'Renderer' attached to the "Figter" game object, but a script is trying to access it.
You probably need to add a Renderer to the game object "Figter". Or your script needs to check if the component is attached before using it.
ShipOrbitPlanet.Update () (at Assets/System Scripts/ShipOrbitPlanet.cs:13)

But its sub object(s) do. Is there anyway to get the visibility status of an object without a Renderer?

No, by definition an object without a renderer is never rendered and therefore can't become invisible since it's never visible. If by sub objects you mean children, then you can have them notify the parent, using SendMessageUpwards or another method.

I've used the following code to figure out the visibility state of my object. Based on the answer @Eric5h5 wrote I'm guessing there is no better way. I'de welcome comments on the code if you have any.

using UnityEngine;
using System.Collections;

public class ShipOrbitPlanet : MonoBehaviour {
    private Transform _transform;
    private float _noBounce;
    private int mode = 0;
    private GameObject _orbits;

    // Use this for initialization
    void Start () {
        _transform = transform;
    }

    // Update is called once per frame
    void Update () {
        if (_noBounce == 0 && mode == 1) {
            Vector3 screenPoint = Camera.main.WorldToScreenPoint(_transform.position);
            if (screenPoint.x < 0 || screenPoint.y < 0 ||
                screenPoint.x > Screen.width || screenPoint.y > Screen.height) {
                SystemController.instance.SetFocus(null);
                transform.localScale *= 20;
                if (gameObject.GetComponentInChildren<ShipControls>()) {
                    gameObject.GetComponentInChildren<ShipControls>().Scale *= 10;
                }
                _orbits.SetActiveRecursively(true);
                mode = 0;
                _noBounce = 0.5f;
            }
        }

        // Prevent bouncing between zooms
        if (_noBounce > 0)
            _noBounce -= Time.deltaTime;
        else
            _noBounce = 0;
    }

    void OnTriggerStay(Collider Obj) {
        if (_noBounce == 0 && Obj.gameObject.tag == "Planet" && mode == 0) {
            // We hit a planet, make sure we are on screen before we zoom
            Vector3 screenPoint = Camera.main.WorldToScreenPoint(_transform.position);
            if (screenPoint.x > 50 || screenPoint.y > 50 ||
                screenPoint.x > Screen.width - 50 || screenPoint.y > Screen.height - 50) {
                SystemController.instance.SetFocus(Obj.gameObject);
                transform.localScale /= 20;
                if (gameObject.GetComponentInChildren<ShipControls>()) {
                    gameObject.GetComponentInChildren<ShipControls>().Scale /= 10;
                }
                _orbits = GameObject.Find("SystemOrbits");
                _orbits.SetActiveRecursively(false);
                mode = 1;
                _noBounce = 0.5f;
            }
        }
    }
}