How to respawn objects After destroyed?

I am very new on developing games. I decided to make a game simply with a player and 5 different objects around it. Any time player collides with the one of the object, then all objects destroyed and respawn again. So far i managed to destroy them but couldt respawn them.

Could you please help me about it, Thank you :slight_smile:

here is the code

public class collectibles : MonoBehaviour
{
         public GameObject[] spawncollectable;
         bool isobjdestroyed=false;
    void Start()
    {
        float radians = 2 * Mathf.PI * 1.3f;
        float vert = Mathf.Sin(radians);
        float horiz = Mathf.Cos(radians);
        var spawnDir = new Vector3(horiz + Random.Range(-0.1f, 1.3f), 0.2f, vert + Random.Range(-0.1f, -1.3f));
        var spawnPos = transform.position + spawnDir;
        Instantiate(spawncollectable[Random.Range(0, spawncollectable.Length)],spawnPos, Quaternion.identity);
    }
    private void Update()
    {
        if (isobjdestroyed == true)
        {
            float radians = 2 * Mathf.PI * 1.3f;
            float vert = Mathf.Sin(radians);
            float horiz = Mathf.Cos(radians);
            var spawnDir = new Vector3(horiz + Random.Range(-0.1f, 1.3f), 0.2f, vert + Random.Range(-0.1f, -1.3f));
            var spawnPos = transform.position + spawnDir;
            Instantiate(spawncollectable[Random.Range(0, spawncollectable.Length)], spawnPos, Quaternion.identity);
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            GameObject[] obje = GameObject.FindGameObjectsWithTag("obj");
            foreach (GameObject o in obje)
            {
                GameObject.Destroy(o);
                isobjdestroyed = true;
            }
           
        }
    }
}

You can check Step 2

为什么要销毁对象呢?建立Obj的过程会消耗性能,除非你在很长一段时间不再使用,才会去销毁他。如你的需求,既然他们会在死亡后很快重生,可以使用SetActive禁用他们。
你所所用的实例化方法Instantiate,是克隆一个对象,因为你已经将对象销毁,因此在实例化的时候当然不会克隆成功。 将你代码中实例化的部分,变成SetActive(true);销毁对象的部分,变成SetActive(false)。即可解决。