Question by
Diveye · Nov 15, 2016 at 03:21 PM ·
gameobjectinstantiatearray
Multiple Instantiations not working
Hi everyone! I've got a problem right now and I havn't managed to find a solution on the net yet... I've defined two prefabs, "ring" and "checkpoint". When I try to instantiate these two prefabs in a script, one after the other, the first one is created, but not the second one.. What am I doing wrong?
public GameObject ring = null;
public GameObject checkpoint = null;
private GameObject[] ringlist = null;
private GameObject[] checklist = null;
private Vector3 current_position;
void Start()
{
checklist[0] = Instantiate<GameObject>(checkpoint);
ringlist[0] = Instantiate<GameObject>(ring);
current_position = transform.position;
ringlist[0].transform.Translate(current_position.x + UnityEngine.Random.Range(-10f, 10f), current_position.y + UnityEngine.Random.Range(-10f, 10f), current_position.z + UnityEngine.Random.Range(-10f, 10f));
checklist[0].transform.position = ringlist[0].transform.position;
checklist[0].GetComponent<Renderer>().enabled = true;
transform.LookAt(checklist[0].transform);
}
The bug happens on the first two lines of the void Start() as only the checklist prefab is created, not the ringlist. Prefabs were correctly configured in the editor and work perfectly independantly.
Thanks!
Comment