Instantiate With OnTrigger in Unity3D

If your game need to instantiate an object based in ontrigger function this tutorial will help you.

don’t forget to comment if you face any problem  🙂

using UnityEngine;

public class Spawner : MonoBehaviour {

    public float delayerTimer = 1.5f;
    public GameObject ob;
    float timer;
    bool spawne = false;


    void Start ()
    {
        timer = delayerTimer;
    }

    void Update ()
    {

         if (!spawne)
            return;

        timer -= Time.deltaTime;

        if (timer <= 0)
        {
            Instantiate(ob, transform.position, transform.rotation);
            timer = delayerTimer;
            spawne = false;
        }
    }

    void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("collided");
            spawne = true;
        }
    }
}