I am trying to optimize CPU usage for the game so I stop rendering when the object is out and render it again when it come back to screen. But the second part I can’t get it to work. The Cat disappeared but never appeared again even I could see it in the Hierachy in editor.
The code is followed:
using UnityEngine;
public class CatUpdater : MonoBehaviour {
private CatController catController;
void Start () {
catController = transform.parent.GetComponent<CatController>();
}
void UpdateTargetPosition()
{
catController.UpdateTargetPosition();
}
void GrantCatTheSweetReleaseOfDeath()
{
Destroy( transform.parent.gameObject );
}
void OnBecameInvisible()
{
renderer.enabled = false;
catController.OnBecameInvisible();
}
void OnBecameVisible()
{
if (!renderer.enabled)
{
Debug.Log("Cat is visible " +gameObject.name);
renderer.enabled = true;
}
}
}