I need to have a function the will return a reference to the nearest instance of a prefab/game object. Nearest to my player object that is. Are there any unity functions that achieve this and if not how would i go about codeing one? Thanks in advance to any one who can help!
1 Answer
1If they have colliders on them, you could make use of this: http://unity3d.com/support/documentation/ScriptReference/Physics.SphereCastAll.html and sort the results by distance.
Maybe take a look at Physics.OverlapSphere(): http://unity3d.com/support/documentation/ScriptReference/Physics.OverlapSphere.html
– Bunny83Thanks Man that done the trick for me,you wouldn't by any chance no how to change the variable of a script attached to the player from within another object would you.
– anon85599651http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html and http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html
– DaveA