- Home /
Comparing position on Update or using camera visibility?
Hello ^^ I have a game where some couroutines start when their game objects are in the field of the camera which follows the player.
Will it be better if I compare the distance between the camera and the object to start those or should I just stick to OnbecameVisible/Invisible?
Thank you ^^
Answer by Leycarno · Feb 14, 2019 at 12:49 PM
Create a Trigger (Sphere?), put it as child of the cam and use Trigger Events. With OnTriggerEnter + OnTriggerExit you can activate / deactivate the desired state of the Intruders.
@Leycarno isn't the trigger detection more ressource consu$$anonymous$$g?
Some Coroutines are more resource consu$$anonymous$$g than one Trigger. You can improve the performance by edit the Layer Collision $$anonymous$$atrix, but One Trigger is nothing versus Coroutines. How did you currently recognize objects in the field of view of the player?
Currently I am using onBecameVisible, Coroutines are a must (they are for spawning ennemies) So the trigger or the to methodes above are only there two start the coroutines when the spawner is in field