Hi everyone! So I’m trying to write an script to make an AI find an enemy constantly, but I’m doubting which script is more efficient:
-
Use a sphere collider and check onTriggerEnter, onTriggerStay, and onTriggerExit methods to know when to attack.
-
Use GameObject.FindGameObjectsWithTag(“Enemy”) to get al Enemies in the scene al later search which one is the closest to the AI. The problem is this method must be executed every frame with every AI in the secene and maybe is more inefficient than the Sphere Collider one.
So my question is, knowing there will be several AI in the secene, which script is more efficient?
Thanks!