Hello everyone A lil stuck in here when I´m trying to spawn an object only ONCE when two objects collide. here´s the code. Thanks in advance.

public GameObject Maze2;
public Transform Spawnpoint;

public void Update()
{

    if (GameObject.FindGameObjectWithTag("StarLevel2") == null)
    {

        Destroy(gameObject, .2f);
        Instantiate(Maze2, Spawnpoint.position, Spawnpoint.rotation);

    }
}

Hi,

It is not clear why are you using the Update method, if you said that you want to spawn an object when two objects collide, then use OnTriggerEnter or OnCollisionEnter.

But if you want to keep your code, why are you not spawn the object first, and then destroy your gameobject?

And if you want to keep your code like this, i suggest you to use a bool variable. I don’t know if this is the most recommended method but i think it works.

 public GameObject Maze2;
 public Transform Spawnpoint;
 private bool _isNull = true;

 public void Update()
 {
     if (GameObject.FindGameObjectWithTag("StarLevel2") == null)
     {
         Destroy(gameObject, .2f);
         if(_isNull)
         {
         Instantiate(Maze2, Spawnpoint.position, Spawnpoint.rotation);
          _isNull = false;
         }
     }
 }