- Home /
Instantiate object method repeating exponentially
So I have a game and pipes need to spawn in random places, and it works fine at the start, but then the pipes start to multiply how many spawn each frame for some reason, and I could not find an article about it. I have tried coroutines but to the same result. I believe it has something to do with the random genrator. I have an input system to spawn. Here are the methods:(changed)` public Vector3 spawn1; public Vector3 spawn2; public Vector3 spawn3; public Vector3 spawn4;
public Vector3 spawnPos; private int spawnPosNumber; public GameObject pipe; // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
}
public void Spawn()
{
Instantiate(pipe, new Vector3(0, Random.Range(5,-5)), transform.rotation);
}`
Answer by MarekRimal · Apr 08 at 02:15 PM
Show me your Spawner class and Pipe class. If the spawning rate grows exponentially then you are probably calling the Spawn method from within the Pipe class and on every spawned pipe, is that correct?
My pipe does not have a script yet, just the spawnManager empty game object.
Then show me the script which is calling the Spawn method. And the script above is attached to what?
this is a screenshot of how it is being called using the input manager. The Script is attached to the SpawnManager(empty).