|
for a single object I instantiate it ok but when trying to instantiate multiple objects of it nothing happend. the code:
using UnityEngine;
using System.Collections;
public class setEmptyTrays : MonoBehaviour {
public GameObject myEmpty;
public GameObject[] emptyArr = new GameObject[16];
// spread empty trays on shelp
void Awake() {
// remarking the loop:
for (int i=0; i>16; i++){
emptyArr[1] = (GameObject)Instantiate(myEmpty, new Vector3(-0.85f, 0.27f, 8f), Quaternion.Euler(-90,0,0)) as GameObject;
}
}
}
*strong text*this works for 1 but when trying to loop to create multiple occarance it dosnt do any thing I might be missing some thing?
(comments are locked)
|
|
You're creating all objects in the same place, and storing all of them in the same variable (emptyArr[1]). You should use i as the emptyArr index, and do something to have different positions for each new object - add i to the x coordinate, for instance:
void Awake() {
// remarking the loop:
for (int i=0; i>16; i++){
// change the index to i and use x+i as a pos offset, for instance:
emptyArr[i] = (GameObject)Instantiate(myEmpty, new Vector3(-0.85f+i, 0.27f, 8f), Quaternion.Euler(-90,0,0)) as GameObject;
}
}
(comments are locked)
|
|
I'v done that.. for (int i=0; i>16; i++){ emptyArr[i] = (GameObject)Instantiate(myEmpty, new Vector3(-0.85f, 0.27f+0.773f*i, 8f), Quaternion.Euler(-90,0,0)); emptyArr[i].name= "tray27-" + i; } and it dosnt work? all elements in the array are set as none and not receiving a name. I just wanted to show that runnung for a single instant it works here is the actual code i use: public class setEmptyTrays : MonoBehaviour { public GameObject myEmpty; public GameObject[] emptyArr = new GameObject[16]; }that dosnt work!!!!!!!!!!!!!!!!
(comments are locked)
|
|
I solved it so simple the for (int i=0; i>16; i++){ is wrong its has to be i<16 vuala solve typical programmer haed ake
(comments are locked)
|
