- Home /
Spawn object
So I asked about this before, and thought that I knew what I was doing but then i got side tracked and did a bunch of other stuff and when it came back it I couldn't figure it out, so i know your probably going to frown at me but i need help here again, my script is below, but I know im making an obvious mistake but i dont know what to do, how do i declare the Items? i thought i would do it in the Inspector, but now im not sure
var GameObject = new Array(5);
GameObject[0] = GameObject;
GameObject[1] = GameObject;
GameObject[2] = GameObject;
GameObject[3] = GameObject;
GameObject[4] = GameObject;
function Start () {
Random.round(Mathf.random()*4);
}
function Update () {
}
Answer by Seth-Bergman · Jul 20, 2012 at 03:16 AM
var myArray : GameObject[] = new GameObject[5];
then to initialize, you could simply drag and drop in the inspector, or use GameObject.FindGameObjectsWithTag or something similar to initialize dynamically..
you can access the members as:
myArray[0] , myArray[1] , etc..
so:
myArray[0] = GameObject.FindWithTag("Player");
...(for example)
Your answer
Follow this Question
Related Questions
Spawn issue - Duplication of Object 1 Answer
Unity Engine issue... 1 Answer
Problem with spawning script 1 Answer
Spawn Script Issue 0 Answers