I have a GameObject, a script is thrown on it, on which Instantiate is executed, which is declared in the ob variable.
public class spawnPrefabs : MonoBehaviour { public GameObject[] item = new GameObject[5]; public GameObject ob; void Start () { StartCoroutine(Inst()); } IEnumerator Inst() { int addXPos = Random.Range(0,4); Vector3 spawnPos = gameObject.transform.position + new Vector3(addXPos, 0, 0); yield return new WaitForSeconds(1.5f); ob = Instantiate(item[Random.Range(0, 5)],spawnPos,Quaternion.identity); Repeat(); } void Repeat() { StartCoroutine(Inst()); } } There is also an invisible GameObject under the stage with Box Collider.
public class triggerDetect : MonoBehaviour { void OnTriggerExit(Collider other) { Destroy(other.gameObject); } } I need to prefab element that entered the trigger, retired, so as not to litter the scene with identical objects.
UPD: I forgot to note that I have a 2D project. As decided: OnTriggerEnter => OnTriggerEnter2D (Collider2D other) . It all worked!
I am new to Unity and to C # as a whole, do not judge me.


OnTriggerExitwithOnTriggerEnterand write a triteDebug.Log("я тут");insideDebug.Log("я тут");and check if it works. - Alexey Shimansky