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, 2011 at 08:15 PM

Caiuse gravatar image

Caiuse
882 258 204 221

(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, 2011 at 08:34 PM

loopyllama gravatar image

loopyllama
1.5k 1 5 22

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, 2011 at 03:32 AM Alec Slayden
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Apr 27, 2011 at 08:32 PM

flaviusxvii gravatar image

flaviusxvii
5.2k 47 37 67

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

x2135
x2127
x554

asked: Apr 27, 2011 at 08:15 PM

Seen: 1550 times

Last Updated: Apr 27, 2011 at 08:15 PM