- Home /
Cache a lot of object transforms in a builtin array? (iPhone)
I need to reset my player with pre-set position and orientation.
I have an arbitrary number of cube's (with correct orientation and positioning) around my level. I could like to check the player distance against all of them, and spawn him on the closest available point.
The question, is how can I get all of those objects into a built-in array in my Start() function? To simplify things, they are all a child of an object called SpawnPoints.
So, I need the blanks filled in here..
var spawnPoints : Transform[];
function Start() { // Find all the children's transforms of SpawnPoint (which could be about 30 or so, who knows) and put them into the array. }
function Spawn() { // This bit I know how to do :) // Check distance // Spawn from the nearest and match orientation }
Answer by Jessy · Sep 02, 2010 at 07:12 AM
There should be a way to do this with Generics in 3.0, but the syntax isn't documented (for JavaScript). In the meantime, put this in Start():
spawnPoints = new Transform[spawnPointParent.GetComponentsInChildren(Transform, true).Length - 1];
var i = 0;
for (var child in spawnPointParent) {
transforms[i] = child;
++i;
}
Ideally, you could do this outside of Start(); that is, run an Editor script and save the array before you build the game. Is that possible? It won't matter that it's not a great way of doing it, if you've got the horsepower of a Mac and as much time as you want to run the function.
Your answer
Follow this Question
Related Questions
Can't do spawning 0 Answers
Need to change direction of transform? 2 Answers
multidimensional builtin vector3 array? 3 Answers
LookAt transform plus a y value 1 Answer
Move object to raycast point. 3 Answers