Getting clones of an object help!

var object : GameObject[];
object = GameObject.FindGameObjectsWithTag("Hero");

function Update()
{
    var distance = Vector3.Distance(object.transform.position, transform.position);
}
ERROR:

Assets/B33fScripts/getAllTags.js(6,45): BCE0019: 'transform' is not a member of 'UnityEngine.GameObject[ ]'. 

I’ve searched all over the place to the answer for this, since this is basically I’m new to this FindAllGameObjectsWithTag. I’ve tried changing GameObject’s “G” to capital and uncapital and didn’t seem to work. I couldn’t understand why GameObject[ ] and GameObject are different, so why is transform not sensing?

You’ll probably want to grab the transform with GetComponent. Not sure though.

Accessing the transform via the ‘transform’ property should be equivalent.

Hi,

What Jesse Anders sayd is true if you want to find an GameObject in your world you just need to declare the variable of the gameObject just like you`ve maded.

var object : GameObject; do not use [ ] because when you use this [ ] you are declaring that its an array.

Then if you want to find an object with a tag just use this:

object = GameObject.FindWithTag(“your tag”)

If you want to clone an object use this function: Instantiate() just google for this function on unity documentation very helpfull.

GameObject won’t work as well, as I tested it before I’ve even opened this thread, but anyway, here is the error anyway.

(1,43): BCE0022: Cannot convert ‘UnityEngine.GameObject[ ]’ to ‘UnityEngine.GameObject’.


I'm sorry if I wasn't clear enough. This is a enemy AI and this is the beginning part of the script. I want it to chase my team mates that has a string of "Hero" instead of just defining all my team mates considering this game spawns a lot of team mates, as in a war. I don't need a full script, just a fix of this and I could finish the rest :)

Bump