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?
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