x


transform array gives error. why?

I get an invalidcast excpetion error here and I can't figure out why. I have a transform variable, and a transform array. I populate the array when it wakes up but when I try to assign the variable to one of the transforms in the array I get an invalidcastexception error. anyone know why?

var respawnpoint : Transform;
var respawnpoints = new Array (Transform);

function Awake()
{
    //GET A LIST OF ALL SPAWN POINTS AND PUT THEM IN respawnpoints ARRAY.
    respawnpoints.push(gameObject.Find("SpawnPoint1").transform);

}
function chooseSpawn()
{
    for(i=0;i<respawnpoints.length;i++)
    {
        //deternmine which spawn point is best. 
        respawnpoint = respawnpoints[i];
    }
more ▼

asked Oct 10 '10 at 08:10 PM

Jordan Miller 2 gravatar image

Jordan Miller 2
348 47 51 57

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

1 answer: sort newest

You're not creating an Array of Transforms, you're creating an Array with one element - the type Transform.

Arrays are always arrays of Objects. You need to cast to Transform a la

respawnPoint = respawnPoints[i] as Transform;

more ▼

answered Oct 10 '10 at 08:19 PM

Loius gravatar image

Loius
10.9k 1 12 43

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

x2030
x1396
x38
x6

asked: Oct 10 '10 at 08:10 PM

Seen: 1274 times

Last Updated: Oct 10 '10 at 08:10 PM