- Home /
How do i reload a level but not all objects?
So basically I want to remove coins that I have collected when reloading. fx. I collect 3 coins and then die (game over). how do I do so those exact 3 coins don't respawn?
public AudioSource coin;
void OnTriggerEnter2D(Collider2D col)
{
coin.Play();
ScoreTextScript.coinAmount += 1;
Destroy(gameObject);
}
what do I need to add to this script for it to work
Answer by surfuay · Jan 18, 2019 at 02:37 AM
are you trying to reset your counter and load the level
hey, sorry i was trying to get a clearer understand of what you want to accomplish, when i reload a level in my game the counter resets but everything else continues,
your code is seems fine, which is why i wanted clarification
He's not talking about the counter, he's talking about the gameObjects. When a coin is collected, that gameObject should no longer exist when the scene is restarted. Also, if you want to ask him a question, don't post it as an answer; add it as a comment ins$$anonymous$$d.
Answer by Sabre-Runner · Jan 18, 2019 at 04:53 AM
I would do it by having a reference array in your Game Manager script that references each coin. When you collect a coin, save some info in PlayerPrefs. When a level is loaded, Game Manager should check PlayerPrefs and only show the coins which haven't been collected.
Your answer
![](https://koobas.hobune.stream/wayback/20220612185945im_/https://answers.unity.com/themes/thub/images/avi.jpg)