Question by
blakeadean · Aug 09, 2016 at 12:05 AM ·
clonesobject pool
I am getting endless clones while activating objects from a pool
This code seems to work as long as there is no Random.Range however, I need the random pacement. Any help would be appreciated.
void Scroll (){
for (int i = 0; i < stars.Count; i++) {
if (!stars [i].activeInHierarchy) {
stars [i].transform.position = new Vector2 (Random.Range (12f, 20f), Random.Range (-6f, 6f));
stars [i].transform.rotation = transform.rotation;
stars [i].SetActive (true);
break;
}
}
}
here is the pooling code just in case
void Start () {
self = GetComponent<Rigidbody2D>();
stars = new List<GameObject>();
for (int i = 0; i < poolsize; i++) {
GameObject obj = (GameObject)Instantiate (star);
obj.SetActive(false);
stars.Add(obj);
}
Invoke ("Scroll", .2f);
}
Comment
Answer by blakeadean · Aug 09, 2016 at 12:42 AM
Never mind, sorry for the useless post... I had the script coupled to the actual star object instead of the camera causing the infini-loop. I separated the movement into it's own script for the star and retooled the pooler and spawner tact right on the camera.