using UnityEngine;
using System.Collections.Generic;
public class Pool : MonoBehaviour {
public GameObject RedS; // this and other three public objects below are not a problem
public GameObject CyanS;
public GameObject OrangeS;
public GameObject GreenS;
public GameObject[] objects;
public int[] number;
public List<GameObject>[] pool;
// Use this for initialization
void Start () {
Instantiate(RedS, new Vector3(-6.0f,-9.0f,-0.4f), Quaternion.identity);
Instantiate(CyanS, new Vector3(-2.0f,-9.0f,-0.4f), Quaternion.identity);
Instantiate(OrangeS, new Vector3(2.0f,-9.0f,-0.4f), Quaternion.identity);
Instantiate(GreenS, new Vector3(6.0f,-9.0f,-0.4f), Quaternion.identity);
instant();
}
void instant(){
pool = new List<GameObject>[objects.Length];
for(int count=0;count < objects.Length ; count++)
{
pool[count] = new List<GameObject>();
for(int num=0;num<number[count];num++)
{
GameObject temp = (GameObject)Instantiate(objects[count]);
temp.transform.parent = this.transform; // MAYBE HERE
pool[count].Add (temp);
}
}
}
public GameObject activate(int id, Vector3 position, Quaternion rotation)
{
for(int count = 0; count < pool[id].Count ; count++)
{
if(!pool[id][count].activeSelf)
{
pool[id][count].SetActive(true);
pool[id][count].transform.position = position;
pool[id][count].transform.rotation = rotation;
return pool[id][count];
}
}
return null;
}
public void deActivate(GameObject deActivateObject)
{
deActivateObject.SetActive(false);
}
}
Please look at this code
Here as you see in the picture, i want only the children of pool to generate but at the start of game whole bunch of object pool gets generated which i dont want.
What is wrong with this code ?