x


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

more ▼

asked Sep 20 '11 at 12:29 AM

GameNewb gravatar image

GameNewb
1 2 2 2

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Sep 20 '11 at 01:17 AM

save gravatar image

save
8.2k 22 31 62

Thanks! Not even my question but the idea of trigger areas will help me soon. =)

Sep 20 '11 at 02:14 AM Essential
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Sep 20 '11 at 02:08 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x790
x355
x322
x79
x49

asked: Sep 20 '11 at 12:29 AM

Seen: 1019 times

Last Updated: Sep 20 '11 at 02:14 AM