- Home /
 
               Question by 
               SavageX370 · Sep 19, 2018 at 07:28 PM · 
                c#fixedupdatespawning problemsobject pool  
              
 
              How can I control Spawn speed/rate from an Object spawner? I'm new to Unity and scripting, and would like to delay the spawn rate of objects coming out of an ObjectPooler.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CubeSpawner : MonoBehaviour {
 ObjectPooler objectPooler;
 private void Start()
 {
     objectPooler = ObjectPooler.Instance;
 }
 // Update is called once per frame
 void FixedUpdate ()
 {
     ObjectPooler.Instance.SpawnFromPool("Cube", transform.position, Quaternion.identity);
 }
}
               Comment
              
 
               
              Answer by Bravil · Sep 19, 2018 at 08:11 PM
Hi, there are many ways to do this, an easy one is to use InvokeRepeating instead of the FixedUpdate. You can do something like this:
 ObjectPooler objectPooler;
     public Float spawnRate;
 
     private void Start()
     {
         objectPooler = ObjectPooler.Instance;
         InvokeRepeating("Spawn", 0, spawnRate);
     }
 
     void Spawn()
     {
         ObjectPooler.Instance.SpawnFromPool("Cube", transform.position, Quaternion.identity);
     }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                