N
N
Nikita Polishchuk2020-11-16 22:28:21
Unity
Nikita Polishchuk, 2020-11-16 22:28:21

How to fix Unity spawner?

The objects generated by the spawner are destroyed by the user, but if the 1st object (which is duplicated) is destroyed, then the objects stop spawning. How can I fix it?

using System.Collections;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    public Transform SpawnPosition;
    public GameObject Watches;
    public float TimeSpawn;

    void Start()
    {
        StartCoroutine(SpawnSD());
    }

    void Repeat()
    {
        StartCoroutine(SpawnSD());
    }

    IEnumerator SpawnSD()
    {
        yield return new WaitForSeconds(TimeSpawn);
        Instantiate(Watches, SpawnPosition.position, Quaternion.identity);
        Repeat();
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question