I want to toggle an object's active state using the camera view:
- when the object leaves the view it deactivates
- when the object enters the camera's view it activates
I'm using this to control the activity of objects in a carousel like this
I did this with a coroutine, but in my project the fps is falling a lot because of the coroutine.
I've already used OnBecameVisible
and isVisible
but that's not it since they only work with a renderer.
public void next() {
StartCoroutine(On(waitnext));
}
IEnumerator On(float waitnext) {
yield return new WaitForSeconds(waitnext);
myArray[Selecao].SetActive(false);
Selecao++;
if(Selecao > myArray.Length - 1) {
Selecao = 0;
}
yield return new WaitForSeconds(waitnext);
myArray[Selecao].SetActive(true);
}
public void previous() {
StartCoroutine(On2(waitprevious));
}
IEnumerator On2(float waitprevious) {
yield return new WaitForSeconds(waitprevious);
myArray[Selecao].SetActive(false);
Selecao--;
if(Selecao < 0) {
Selecao = myArray.Length - 1;
}
yield return new WaitForSeconds(waitprevious);
myArray[Selecao].SetActive(true);
}
GeometryUtility.CalculateFrustumPlanes
andGeometryUtility.TestPlanesAABB
. \$\endgroup\$