Hello all,
I’m newbie and trying to test small game. My problem now: How to detect a gameobject “see” by main camera. Then add a alarm (popup/button …) to it. My scene have only 2 gameobject and maincamera. When i rotate it, same time a gameobject will behind another, so if it’s visible: add alarm for it.
I tested with renderer.isvisible but dont. Hopeffuly will have any help.
Thanks. Quen.
Renderer.isVisible is true or false based on whether or not the object needs to be rendered, which is not always the same as the object being in view, i.e. contributing pixels to the screen. In your case, it sounds like you’d like to detect whether an object is occluded by another, which is not the same condition as the one that sets renderer.isVisible.
Unity does include occlusion culling algorithms, but unfortunately, those are a Unity Pro feature and I’m not sure the API offers access to the results of its calculations, that is, whether it gives you callbacks that occur when objects become occluded. So you need to come up with something else.
A simple, and relatively easy approach to develop is to calculate the screen-space bounding box of your objects. If the screen-space bounding box of one object completely envelops the other (you’d use Rect.Contains), then test their depths. If the enveloped object has a greater depth than the enveloping object, it is likely occluded. This approach can fail for a number of reasons, particularly if the objects can intersect, but it might work in your situation.
THIS may help you…Dharmesh
Yah, test ok with Occlusion Culling. exactly what i want. So now i want add popUp/Button when gameObject appear, this popup much be move follow the object if rotate group. How can I do? Thanks.[32640-screen+shot+2014-09-19+at+10.29.35+pm.png|32640]
P/S. this solution just good for Sphere object. With another shape, i think not appropriate.