Hello, Community!
Now I`m making a Unity2D game. I have got a problem in self – destroying the object after the time given. My script creates four objects automatically with script of self-destroying. But if this script destroys the object, then all objects are destroying.
Code of the script:
using UnityEngine;
using System.Collections;
public class WorldStop : MonoBehaviour {
public int Interval;
void Start()
{
StartCoroutine(just(Interval));
}
private IEnumerator just(float Interval)
{
while (true)
{
yield return new WaitForSeconds(Interval / 1000);
Destroy(gameObject);
}
}
}
Who can help me to solve this problem?