Game Development Reference
In-Depth Information
Detecting the object visibility
Perhaps, the simplest and more direct visibility test for objects in Unity is
determining when an object becomes visible and invisible to any camera. The
two companion events, OnBecameVisible and OnBecameInvisible , are called
automatically on any object with a renderer component, including MeshRenderer
and SkinnedMeshRenderer . It's not, of course, called on empty game objects even
if they fall within the view of the camera, as they (technically speaking) contain no
visible parts, despite all parts being spatially located. You can handle these events,
as shown in the following code sample 5-2:
//----------------------------------------------
using UnityEngine;
using System.Collections;
//----------------------------------------------
public class ViewTester : MonoBehaviour
{
//----------------------------------------------
void OnBecameVisible()
{
Debug.Log ("Became Visible");
}
/----------------------------------------------
void OnBecameInvisible()
{
Debug.Log ("Became Invisible");
}
//----------------------------------------------
}
//----------------------------------------------
 
Search WWH ::




Custom Search