If statment continuous to run even tho it should not, I think

I am just wondering, does the zIncrementer increase by one each frame? Because when I clone the 1x1x1 prefab I see hundreds maybe thousands of clones in the hierarchy, but in the scene, I can only see 5-10 of the cubes. If I don’t stop the game so the script stops (a couple of seconds), unity will completely freeze.

Everything is working perfectly fine, it’s just that it clones too many.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DuplicateSnow : MonoBehaviour
{
public GameObject SnowCube;
private float zIncrementer;
// Update is called once per frame
public void Update()
{
if (zIncrementer <= 10)
{
Instantiate(SnowCube, new Vector3(SnowCube.transform.position.x, SnowCube.transform.position.y, zIncrementer), Quaternion.identity);
zIncrementer += 1;
}
}
}

Is this script also on the ones you’re duplicating? It’s gonna exponentially balloon upward in count pretty quickly if so.

1 Like