So here is the thing: in my game I have coins scattered all around the level, these are simple GameObjects that get destroyed when the player touches them right after adding a +1 to the coin counter. My problem is that when the player dies I use the Application.loadlevel to restart the level, it works okay but I want all the coins that the player already picked up in their previous play to stay destroyed… which doesn’t happen, of course, since the loadlevel function restarts everything… is there a way to keep my coins destroyed while everything else gets resetted after the player dies? thanks in advance!!
Easiest way would be to use a static class that maintains a list of which coins have been collected, and check that class each time the level is loaded.
Check the tutorial on saving and persistent data. Any method will work, and it mostly depends on the structure of your game which you choose.
One of the ways I can think to keep it simple would be to make a global Coin_Behaviour that could have inside all the things the Coin does ( calling Sounds, Rotating, floating up and down and whatever) and add a boolean Coin_Active that gets called everytime the Level is loaded, that way when the Player Collides with the Coin, Coin_Behaviour will change Coin_Active to false and the function would be:
function OnLevelWasLoaded()
{
if ( Coin_Active == false )
{
this.Destroy();
}
}
and since the Script is global for each Coin you can just make your script with this instead of actually referring to any objects, that way Each Coin behaves for himself without really interacting with others