Hi
I have a Main Camera. And I want to deactivate object if they aren’t visible by the Main Camera. And if it is. Then it activate
Someone who can help me?
I tried a lot
Like this.
function OnBecameInvisible ()
{
gameObject.SetActive (false);
}
Please help. Thanks in advance
Vector3 position = camera.WorldToViewportPoint(transform.position);
if(position.x<0||position.x>1||position.y<0||position.y>1){
OnBecameInvisible()}
I think that should do it.
p.s. sorry for the horrible formatting I’m using an ancient browser.
EDIT:
Ok I feel dumb as I now realize that OnBecameInvisible() is a method of the Renderer class. I’m now confused about what the problem is. Is the method not firing when the object moves out of view?
if your trying to make an object invisble do this renderer.enabled = false then set a boolean