how to destroy instatiated prefab behind the player
Hello, I'm making a slope type game where a sphere is rolling down a ramp. The ramp is infinite because I'm instantiating a ramp prefab in front of the player. How do I delete this ramp prefab when it's behind and far away from the player to improve performance?
Answer by Davinder_Singh · Feb 12 at 01:31 PM
You can keep the reference of the instantiated ramps in an List of game objects and check them in a custom update if they r behind player or out of view and then destroy them! E.g. GameObject Ramp=Instantiate(RampPrefab); Ramps.Add(Ramp);
But I would recommend you to use object pooling if you have an infinite runner kind of game for better optimization
Your answer
Follow this Question
Related Questions
Changing rotation of prefab 0 Answers
Saving Instantiated objects,Saving Instantiated objects 0 Answers
All instantiated objects having same location, 0 Answers
Instantiate a prefab and assign it's values 1 Answer
Find instantiated prefab by name 3 Answers