Hi guys,
I made 1 straight road where the character with Main Camera moves only forward. What I’m trying to do is to destroy all the objects behind the Main Camera without using Occlusion Culling.
Someone knows how to do that?
Please help.
Thanks in advance
Yep:
//Presuming you have the item to be tested in a variable called "item"
float distanceToCull = 4f;
var cameraPosition = Camera.main.transform.position;
var vectorToItem = (item.position - cameraPosition);
if(Vector3.Angle(vectorToItem, Camera.main.transform.forward) > 90) //It's behind us
{
//Perhaps ensure it's far enough away
if(vectorToItem.sqrMagnitude > distanceToCull * distanceToCull)
{
//Kill it
}
}
Depending on how your game actually works, put this script on each object:
function OnBecameInvisible () {
Destroy (gameObject);
}