- Home /
Help with making item invisible if not on screen
Ok so you read the title, this is my code so far:
function OnBecameInvisible() {
renderer.enabled = false;
}
So I tried OnBecameVisible but that doesn't work if the object is invisible or renderer is disabled. I thought a Raycast might work but was wondering if there was another better way to do it. Thanks!
Answer by MrLeap · Nov 01, 2012 at 06:49 PM
Read the section about clip planes. Sounds like you're trying to do something called Frustum culling, which in most cases happens automatically.
You can technically calculate the angle between the vector to the object and the camera and if it's greater then the view angle, disable it's renderer.
However, as $$anonymous$$rLeap already said, this is something that Unity does automatically for you. You can test against renderer.isVisible to enable/disable scripts etc. for performance though, which can certainly be useful for optimization purposes.
Your answer
Follow this Question
Related Questions
is there an alternative for raycast that does a plane instead 1 Answer
C# Parsing Error and Unexpected Symbol 1 Answer
How To Invoke RayCastAll? 1 Answer
Problem with raycast shooting 1 Answer
Raycast message problem 1 Answer