finding position of a object in array?

dose anyone know how to find a the possition of a object in a array? hear is my script thanks:) :

#pragma strict
var food : GameObject;
var tailsegment : GameObject;
var tail = new Array ();
var sizeX = 20;
var sizeY = 20;


function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "food")  
{
//food starts hear
Destroy (collision.gameObject);
var position : Vector3 = Vector3(Random.Range(-sizeX, sizeX), 1, Random.Range(-sizeY, sizeY));
Instantiate(food, position, Quaternion.identity);
//tail starts hear
tail.length = tail.length ++;
var tailpos = tail[tail.length].position;//problem hear
Instantiate(tailsegment,tailpos, Quaternion.identity);
//tailsegment.CharicterJoint.connectedBody = tail[tail.length]; //other problems hear but arnt urjent
//tail [tail.length] == tailsegment;
}
}

if your trying to get the last item stored in the array it would be
var last = tail.length > 0 ? tail[tail.length -1] : null;

when you add stuff to the array use .Push instead of modifying length.

I dont mean its position in the array i mean the possition of part of the array in the scene.

im making a snake game so i need it to be, hits the food → destroys the food → instantiates a tail piece → makes the joint conect to the tailpart befor it —> creates a new pice of food.

but thanks anway :slight_smile:

If tail contains gameobjects, position should be transform.position

how would i wright it tho for a object in the array? i need to find the position of the last object in an array. this is were i get the error var tailpos = tail[tail.length ].position but becase position isent a member of Object it dosent work? var tailpos = tail[tail.length ].transform.position dosent work eather becase transform isent a member of Object

this is the code that affects this:

var tailsegment : GameObject;
var tail = new Array ();

function OnCollisionEnter(collision : Collision)
{
tail.length = tail.length ++;
var tailpos = tail[tail.length -1].position;//problem hear
Instantiate(tailsegment,tailpos, Quaternion.identity);
tailsegment.CharicterJoint.connectedBody = tail[tail.length]; //other problems hear
tail [tail.length] == tailsegment;
}

ok i fixed it by using a bulliten array like so:

#pragma strict
var food : GameObject;
var tailsegment : GameObject;
var tail : GameObject[];
var sizeX = 20;
var sizeY = 20;


function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "food")  
{
//food starts hear
Destroy (collision.gameObject);
var position : Vector3 = Vector3(Random.Range(-sizeX, sizeX), 1, Random.Range(-sizeY, sizeY));
Instantiate(food, position, Quaternion.identity);
//tail starts hear
var tailpos = tail[tail.length -1].transform.position;
Instantiate(tailsegment,tailpos, Quaternion.identity);
//var tailsegridge = tailsegment.Rigidbody;
//tailsegment.hingeJoint.connectedBody = tail[tail.length]; //other problems hear but arnt urjent
//tail [tail.length] == tailsegment;
//tail.Push(tailsegment);
}
}