i want to find the gameobjects around my player.
what i want to do is find all the gameobjects within a certain area around my player and activate them.
i am working on an openworld game.
please help.
Do yourself a favor and make it simple, use Unity - Scripting API: Physics.OverlapSphere
This will return all colliders within radius. From there you can access gameObject.
EDIT:
If the objects are not active you may want to create an array and store all objects at Start, then you can perform:
Transform [] array;
void GetInactiveInRadius(){
foreach (Transform tr in array){
float distanceSqr = (transfor.position - tr.position).sqrMagnitude;
if(distanceSqr < rangeSqr)
tr.gameObject.SetActive(true);
}
}
simply use Physics.OverlapSphere
Physics.OverlapSphere (someposition, someradius);