x


Finding the Vector3.Distance or an array of GameObjects

var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");

var distance = Vector3.Distance(enemies.transform.position,transform.position);

if(distance < Vector3(2,2,2)){
//DoSomething
}

This is what i've got so far, obviously transform cannot be accessed with just referencing an array, but how can I find and store the transforms off all the GamObject within the array.

Thanks - C

more ▼

asked Apr 27 '11 at 08:15 PM

Caiuse gravatar image

Caiuse
817 102 110 124

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

2 answers: sort voted first
for (var enemy in enemies)
{
    ... enemy.transform.position ...

but why don't you place a sphere trigger on your player and enemy then listen for the trigger event...

more ▼

answered Apr 27 '11 at 08:34 PM

loopyllama gravatar image

loopyllama
1.5k 1 4 18

Yeah you don't have to store the transform data separately. The gameobjects in your array have all the information included about their transforms, components, parents, etc.

Apr 28 '11 at 03:32 AM Alec Slayden
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Apr 27 '11 at 08:32 PM

flaviusxvii gravatar image

flaviusxvii
4.6k 16 21 48

(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:

x1887
x1878
x500

asked: Apr 27 '11 at 08:15 PM

Seen: 1367 times

Last Updated: Apr 27 '11 at 08:15 PM