- Home /
Activate Object in a Certain Distance
I want to change a Boolean on multiple or a single object when its within a certain distance. Im new to c# and I'd much rather program this game in c#. So i was thinking of having some variables like these.
public int Radius = 1;
public GameObject ActivatedObjects = GameObject.FindWithTag("activate");
Could I set up a function to where it finds game objects with the activate tag (activated objects variable) within a certain distance (radius variable) and than have a Boolean in those objects that were found and change it from false to true or the other way around. Much help is appreciated.
Thanks
Answer by save · Sep 20, 2011 at 01:17 AM
I often use trigger areas that activates objects, this way you won't have to worry about clutching up the overhead to much. While the objects are active I check for a distance > player trigger area (using sqrMagnitude), if it is then disable their demanding components.
This require rigidbodies though, if your game doesn't use physics then run a invoked coroutine checking for sqrMagnitude on the objects.
Thanks! Not even my question but the idea of trigger areas will help me soon. =)
Answer by syclamoth · Sep 20, 2011 at 02:08 AM
See my answer to your duplicate question- http://answers.unity3d.com/questions/168486/changing-booleans-throught-certain-distance.html. You should avoid posting duplicates- remember that when you have below 15 reputation, it takes a few minutes for your questions to be cleared by the moderators! You just have to be patient.
In the meantime, please close and/or delete any duplicate questions.
Your answer
Follow this Question
Related Questions
Activate objects in array based on value 3 Answers
How to click from specyfic distance? 2 Answers
Random Range on the X Axis 0 Answers
Distance between 2 objects exteriors? 1 Answer
Activate an animation by clicking on a separate Gameobject 0 Answers