How to sum up total coins after every level for Game's Home scene.

I am using a game object with dontdestroyonload() to store the coins earned in a level and to add them to get the total coins collected after playing the game n times. Also, this game object is storing the highest score which compares and set the highest score if greater score is achieved. The high score is working fine, but the total coins is not, the coins are added twice than what is really collected. For example if the player collects 10 coins in the game, it add up 20 coins, if next time it collects 6 coins then it adds 12 coins. It shows 32 coins, but in real the player collected 16 coins only.
Take a look at the script that I had used. I am new to unity. Please provide an efficient way to get the total coins collected.

For me, the issue looks like it’s:


void Update()
{
SceneManager.activeSceneChanged += CoinsAdd; ← bad

Every update you are adding another callback to the activeSceneChanged event… eek.
So basically, there could be a thousand callbacks there, and even though you do SceneManager.activeSceneChanged -= CoinsAdd… that only removes one of them.

So this means a few get through and will add more coins, luckily its only twice because 'SwitchPauseMenu.gameOver gets set to false.

My advice is to add the callback to onAwake, then don’t worry about removing it through CoinsAdd.