- Home /
Duplicate Question
OnBecameVisible is not working correctly!
Hi! I want to make a script where if the camera is facing an object, that object needs to become visible or enabled, and if im not facing it, it should get disabled or something. function OnBecameVisible only works if the mesh renderer on that object is enabled, that defeats the purpose of that script. How do I make a script that enables/disables the object if its visible, no matter if its disabled or enabled already? Thanks!
For this script I disabled the mesh renderer in the editor, and its not working :/
#pragma strict
var visible : boolean =false;
function Start () {
}
function Update () {
if(visible ==true){
renderer.enabled = true;
}
}
function OnBecameVisible() {
visible = true;
}
It's working 100% correctly. If you disabled the renderer, there's no way OnBecameVisible can fire. Also, even if the logic made any sense, why would you constantly poll a variable in Update when you could just do the work in OnBecameVisible?
I am just trying to make a script that unity pro has but unity free doesnt. If I am facing a bunch of objects, they will be all rendered, but I want to make it so if some smaller object is behind a bigger object, i want the smaller object to be disabled so it doesnt use up draw calls.
That won't work at all. An object going behind another one doesn't make it invisible. It's still there and perfectly visible, just covered up by objects drawn on top. If you're trying to replicate occlusion culling, you'd have to manually create your own system (which does not involve OnBecameVisible in any way; maybe raycasting or something).
Follow this Question
Related Questions
Detect if entity is visible - renderer.isvisible will not work! 3 Answers
Hide gameobject until certain condition has been met,Hide an object until a condition is met. 2 Answers
Problem is "renderer.isVisible" 3 Answers
If gameObject is invisible - disable it... what's wrong with this code? 1 Answer