Easy . Only instantiate if other is off screen or dead .

I have this script that does work but it keeps cloning clones of clones, What I want is only if the original has left the screen or has been killed to then instantiate it gets to crowded with all of them on screen. So only instantiate if origanl has left screen or been killed

Help thanks

2d and c# code

using UnityEngine;
 using System.Collections.Generic;
 
 // Starting in 2 seconds.
 public class sss : MonoBehaviour {
 
     public Rigidbody2D projectile;
10. 
     void Start() {
         InvokeRepeating("LaunchProjectile", 4.0f, 6.0f);
     }
 
15.     void LaunchProjectile () {
 
         Rigidbody2D instance = Instantiate(projectile);
 
         instance.velocity = Random.insideUnitSphere * 5;

 
 }
          }
     }

You’ll want to store the gameobject you instantiate as a local var to the script, then you will want to use the Renderers isVisible property to figure whether it’s in view of the camera. You could also use camera WorldToScreenPoint to measure whether it’s within the current screen resolution or you can try the Renderers property. This is untested and just put together with notepad++

using UnityEngine;
using System.Collections.Generic;

// Starting in 2 seconds.
public class sss : MonoBehaviour
{
	public Rigidbody2D projectile;
	private Rigidbody2D projectileInstance = null;
	private bool inScreenVisible = false;

	void Start()
	{
		InvokeRepeating("LaunchProjectile", 4.0f, 6.0f);
	}

	void Update()
	{
		if (projectileInstance != null)
		{
			inScreenVisible = projectileInstance.gameObject.GetComponent<Renderer>().isVisible;

			if (isScreenVisible && projectileInstance.gameObject.GetComponent<Renderer>().isVisible == false)
			{
				Destroy(projectileInstance.gameObject);
			}
		}
	}

	void LaunchProjectile()
	{
		if (projectileInstance == null)
		{
			projectileInstance = Instantiate(projectile);

			projectileInstance.velocity = Random.insideUnitSphere * 5;
		}
	}
}