I know this code is sort of messy but I’ve been so bugged today with object pooling just not working out at all. In an earlier script I can’t get it to activate I’ve been trying to rewrite it in mutliple ways but this way doesn’t even create the GameObject into the pool. Its not giving me any errors but its just not creating anything. I’ve already set the game objects for the GameObjects like rowOf1 and such through prefabs. Please check out my other question as well asking why a similar script won’t work.
http://answers.unity3d.com/questions/1327128/code-wont-activate-items-from-object-pool.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RowSpawner : MonoBehaviour
{
public bool isAlive;
float xPos;
Vector3 rowSpot;
public int random;
public GameObject rowOf1;
public GameObject rowOf2;
public GameObject rowOf3;
public GameObject rowOf4;
public int pooledAmount;
public List<GameObject> row1;
public List<GameObject> row2;
public List<GameObject> row3;
public List<GameObject> row4;
void start ()
{
row1 = new List<GameObject> ();
row2 = new List<GameObject> ();
row3 = new List<GameObject> ();
row4 = new List<GameObject> ();
isAlive = true;
InvokeRepeating ("Spawner", 2.0F, 1.0F);
xPos = 0;
for (int i = 0; i < pooledAmount; i++) {
GameObject obj1 = (GameObject)Instantiate (rowOf1);
obj1.SetActive (false);
row1.Add (obj1);
GameObject obj2 = (GameObject)Instantiate (rowOf2);
obj2.SetActive (false);
row2.Add (obj2);
GameObject obj3 = (GameObject)Instantiate (rowOf3);
obj3.SetActive (false);
row3.Add (obj3);
GameObject obj4 = (GameObject)Instantiate (rowOf4);
obj4.SetActive (false);
row4.Add (obj4);
}
}
void update ()
{
}
void Spawner ()
{
random = Random.Range (1, 5);
xPos = xPos + 10F;
rowSpot = new Vector3 (xPos, 0.35F, 0);
if (isAlive == true) {
if (random == 1) {
for (int i = 0; i < row1.Count; i++) {
if (!row1 *.activeInHierarchy) {*
_ row1 .transform.position = rowSpot;_
_ row1 .transform.rotation = Quaternion.identity;
row1 .SetActive (true);
* break;
}
}
}
if (random == 2) {
for (int i = 0; i < row1.Count; i++) {
if (!row1 .activeInHierarchy) {
row1 .transform.position = rowSpot;
row1 .transform.rotation = Quaternion.identity;
row1 .SetActive (true);
break;
}
}
}*_
* if (random == 3) {*
* for (int i = 0; i < row1.Count; i++) {*
_ if (!row1 .activeInHierarchy) {
row1 .transform.position = rowSpot;
row1 .transform.rotation = Quaternion.identity;
row1 .SetActive (true);
* break;
}
}
}*_
* if (random == 4) {*
* for (int i = 0; i < row1.Count; i++) {*
_ if (!row1 .activeInHierarchy) {
row1 .transform.position = rowSpot;
row1 .transform.rotation = Quaternion.identity;
row1 .SetActive (true);
* break;
}
}
}
}
}
}*_