How to get all game objects within a radius?

+1 vote
asked Apr 8, 2015 in Programming by JD Student (300 points)
I'm looking for a cheap way to get all game objects within a given radius without the need for looping thru all game objects in the scene.


1 Answer

+2 votes
answered Apr 9, 2015 by Bugstacker Senior (4,800 points)
selected Apr 9, 2015 by JD
Best answer

Have a look at Physics.SphereCastAll .

SphereCastAll(Vector3 origin, float radius, Vector3 direction, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);

This function will return all hits in the specified radius.

Welcome to Bugstacker Q&A, where you can ask questions concerning Game Development, Programming and Design and receive answers from other members of the community.

Help for