How can enumerate all object in the scene. To be precise how can I pass all object in the scene into array.
Thanks
An easy way to do this is to give all the objects a tag. Then, you can use GameObject.FindObjectsWithTag to retrieve them all as an array.
I think FindObjectsOfType()
or for UnityScript use FindObjectsOfType (Type)
Both return Object[ ] Arrays… personally I think converting that Array to a Dictionary might be useful after that so you can do Flash style references… this is just a theory though.
Defiantly not something one should do more than once I’d think
I dug abit more and found three functions that will do various jobs for you… its of course up to you to sort the results into something usable but hey… ![]()
JS code
var objArray:Array;
function Awake () {
//objArray = FindSceneObjectsOfType (GameObject);
//objArray = FindObjectsOfType (GameObject);
objArray = FindObjectsOfTypeIncludingAssets (GameObject);
}
function Start(){
for(var i=0; i<objArray.length; i++){
Debug.Log(objArray[i].name);
}
}
Only FindSceneObjectsOfType(type) is in the Docs so I don’t know if the other two are supported nor do I know if they will be around over the next couple releases
Thank’s I will test it.
I need this for enuzmerate all enemy ships in the scene and then pass the transform.position to MiniMap. You can check it out here : http://woodgamesfx.com/?page_id=138 , when game start press key M to show you the minimap.
I just have one question about construct minimap. For now I have scene 800 X 600 and I wish create minimap 200 X 100, how can I transform object position from map to minimap ?
Thanks.
An easy way to get a map is to place a camera over the scene and render it to its own rectangle in the corner. Check out the Camera component manual page, especially the part about the normalised viewport rectangle.