//Change this to suit your needs
void Update()
{
if (renderer.IsVisibleFrom(Camera.main))
{
Debug.Log("Still Visible");
}
else
{
Debug.Log("Not visible");
transform.position = new Vector3(x, y, z);
}
}
This will not dynamically spawn object nor destroy it would rather reuse existing.
0
Make your cube into a prefab. Then create a GameObject somewhere in your scene and attach a script to it that spawns the cubes every x seconds.
public Transform MyPrefab;
private float timer = 0f;
void Update() {
timer += Time.deltaTime;
// Spawn a new block every second
if (timer > 1f) {
Instantiate(MyPrefab);
timer -= 1f;
}
}
In the inspector, drag your prefab to the MyPrefab
property of your spawning object so it knows what to instantiate.
You should probably attach a script to your prefab cubes that calls Destroy()
on them once they fall completely off screen.
example s: