- Home /
How would I destroy and respawn an object based on player distance?
Hi guys, so I' m working on a game that has thousands and thousands of objects, because it's a blocky sort of game. Anyways it's randomly generating, and I want it to destroy an object when the player is a certain distance from it, and respawn it when the player gets close again. The objects don't need to hold any data besides their position and what gameObject they are. How would I go about doing this do you think?
Answer by logicandchaos · May 15, 2020 at 10:00 PM
Vector3.Distance
disable and enable the objects rather than destroy, look at object pooling, then keep a list of your objects and use a foreach to loop through checking the distance, if it is more than a certain amount, int maxDistance, for instance, then you disable it, and when you want a new one you enable it.