How can i destroy generated(clones) obstacles

The obstacle are generated using a generate script and gameobject is in the prefabs folder i have attached the gameobject with the generate script the problem is that it wont get destroyed

using UnityEngine;
using System.Collections;
public class Generate : MonoBehaviour
{
public GameObject rocks;
int scr;

	// Use this for initialization
	void Start()
	{
		InvokeRepeating("CreateObstacle", 3f, 3f);
	}
	void OnGui()
	{
		GUI.color = Color.black;
		//GUILayout.Label ("Score is" + scr.ToString ());
	}

	void CreateObstacle()
	{
		Instantiate(rocks);
		scr++;

	}
	void OnBecameInvisible() { 
		// Destroy the bullet 
		Destroy(rocks);
		Destroy(this.gameObject);
	} 

}

you could add a ‘destoryaftertime’ script to your bullets, its what i usually do

just add a float u can edit from inspector and add that to the destroy function that u can simply call from start() or awake()

166412-destroydelay.png

just make side camera colider and when it touch, it destroy

void OnColider(Colider col){
     if(col.name == "ScreenSide")// That the block u placed left to the camera
     {
          //Destroy
     }
}

The reason why its not destroying is because you are trying to destroy the original prefab. You cant destroy prefabs as its not safe to do so, in case of data loss, since its not in the scene. To destroy clones, you need to find the clone objects, either by searching for all the gameobjects called rocks(Clone) and destroying those, or you can tag all generated clones right after theyre instantiated and destroy all objects with that tag. This is just for anyone else who needs a solution for this question as the asker probably wont see it.