- Home /
How to control pooledObject?
I want when the scene was start, a pooledObject will be instantiated each 3s. Then, I want this will be instantiate faster (2s, 1s,...). But I can't, because the instantiate code (in Move() method) must be call in Start() method.
public float moveTime = 3f;
void Start () {
InvokeRepeating("Move", moveTime, moveTime);
}
I can't call Move() method in Update() because It will create many objects each frame loaded. But if Move() method in Start(), It can't update the moveTime variable.
Does someone have any idea? Thanks!
Answer by Woj_Gabel_FertileSky · Mar 05, 2015 at 11:02 AM
You could use Coroutines.
public float timeInterval = 1f;
void Start()
{
StartCoroutine (Do ());
}
public IEnumerator Do()
{
int c = 0;
while(c < 10)
{
Instantiate (object, position, rotation);
c++;
yield return new WaitForSeconds(timeInterval);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613185057im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I can't Implement the Pool system 1 Answer
spawn from pool only if pool has inactive gameobjects 3 Answers
Array is out of range? 0 Answers
How to despawn from another script (PoolManager) 0 Answers
Pooled objects change behavior. 0 Answers