- Home /
 
 
               Question by 
               blackmask86 · Jun 27, 2020 at 12:28 AM · 
                gameobjectinstantiateprefabdeleteondestroy  
              
 
              I cant delete multiple instantiated prefabs
Hello, I have this script
         for (int i = 0; i <= tree1ic; i++)
         {
             Instantiate(tree1, new Vector3(-9.5f, 0, transform.position.z + -295 + 15.0f + i * 15.0f), Quaternion.identity);
             Instantiate(tree1, new Vector3(9.5f, 0, transform.position.z + -295 + 15.0f + i * 15.0f), Quaternion.identity);
         }
 
               Also i try this code
             for (int i = 0; i <= tree2ic; i++)
             {
                 agac1 = Instantiate(tree2, new Vector3(-9.5f, 0, transform.position.z + -295 + 15.0f + i * 15.0f), Quaternion.identity) as GameObject;
                 agac2 = (GameObject)Instantiate(tree2, new Vector3(9.5f, 0, transform.position.z + -295 + 15.0f + i * 15.0f), Quaternion.identity);
             }
         }
 
               I want Destroy this gameObjects but on this function;
     void OnDestroy()
     {
 i want delete from here because i have a road. When road destroyed prefabs cannot destroyed.
     }
 
               Please help me thanks a lot.
               Comment
              
 
               
              Your answer