How to add coins to previous coins collect in previous round

Hello so i want to have a coin bank.What i mean by that is that when you collect lets say 5 coins and when you restart ,in the menu that 5 coins get added up to previous coins got in last round
This is my script ;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public static GameManager instance = null;

    public GameObject scoreTextObject;

    int score;
    Text scoreText;


    void Awake()
    {
        if (instance == null)
            instance = this;
        else if (instance != null)
            Destroy(gameObject);

        scoreText = scoreTextObject.GetComponent<Text>();
        scoreText.text = " " + score.ToString();
    }

    public void Collect(int passedValue, GameObject passedObject)
    {
        passedObject.GetComponent<Renderer> ().enabled = false;
        passedObject.GetComponent<Collider>().enabled = false;
        Destroy(passedObject, 1.0f);

        if (PlayerPrefs.GetFloat(" ")  + score)
        PlayerPrefs.SetFloat(" ", score);

        score = score + passedValue;
        scoreText.text = ": " + score.ToString();
        // update our score UI
    }
}

For some reason it says that cannot implicitly convert float to bool
Please help me

Hey have you found out? I stand infront of the same Problem.

The problem is that you have not initialized your int score variable. In computer science, you eventually learn that you can use integers as booleans since booleans are just binary for on-off or true-false, where 1 is equivalent to true and 0 is equivalent to false. Since you just declare your variable, c# automatically makes any non-initialized variable either null or 0. However, even if it is 0 implicitly, the compiler gets confused and thinks that score is a boolean and thinks you are adding a boolean type with an integer. Honestly, it is what it is. Just change int score to int score = 0.


TL;DR:

Just change int score to int score = 0.

@UnityToMakeMoney is right, it’s better practice to initialise the score.

Instead of PlayerPrefs.SetFloat(), you should use PlayerPrefs.SetInt() as your score variable is int.
Additionally it would make sense, to define a const string that you use as a name and to load the score during awake if the data should be persistent after the game was closed once.

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class GameManager : MonoBehaviour
 {
    private const string scorePrefsName = "PlayerScore";

     public static GameManager instance = null;
 
     public GameObject scoreTextObject = null;

     // Initialize value
     int score = 0;
     Text scoreText;
 
 
     void Awake()
     {
         if (instance == null)
             instance = this;
         else if (instance != null)
             Destroy(gameObject);

         // Add checks, if your public objects exist!

         // Get the value and init to 0 if applicable
         this.score = PlayerPrefs.GetInt(scorePrefsName, 0);
         scoreText = scoreTextObject.GetComponent<Text>();
         scoreText.text = " " + score.ToString();
     }
 
     public void Collect(int passedValue, GameObject passedObject)
     {
         passedObject.GetComponent<Renderer> ().enabled = false;
         passedObject.GetComponent<Collider>().enabled = false;
         Destroy(passedObject, 1.0f);
 
         score = score + passedValue;
         // After the score has been changed, store it and save the prefs
         PlayerPrefs.SetInt(scorePrefsName, score);
         PlayerPrefs.Save();
 
         scoreText.text = ": " + score.ToString();
         // update our score UI
     }
 }

I didn’t compile it, so it’s freestyle without warranty…