Answer the question
In order to leave comments, you need to log in
How to remove an object when it passes through a certain point?
I have a Map object on which all the scripts are dressed and the Ground, Obstacle objects are placed inside it, it also moves backwards relative to the Z axis and when it reaches a certain point, clones of the Map object are created. I need to delete the Map object if it reaches the -100 point. But when he reaches it, his clones are also deleted, and I need each one to be deleted in turn.
Here is the code:
GroundMovement Script:
if (map.position.z <= 0 && !spawned)
{
FindObjectOfType<GroundSpawner>().SpawnWave();
spawned = true;
}
if (map.position.z <= -100)
{
FindObjectOfType<GroundSpawner>().DeleteWave();
}
public void SpawnWave()
{
Instantiate(objToSpawn, map.position + offset, Quaternion.identity);
}
public void DeleteWave()
{
Destroy(objToDelete);
}
Answer the question
In order to leave comments, you need to log in
Does the trigger actually work?
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody . If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question