- Home /
 
Convert type `float' to `bool', Load
A very long question :( In Main Menu I can enable/disable music. I want the Game to keep music disabled if it was disabled during previous play, or enabled if it was enabled during last play. So, I decided to save that value in a file through the script, and in Load script (which executes every time the game starts) I want to check if that value was true or false.
 void OnGUI () 
        {
           if ( GUI.Button( new Rect(10,10,60,20),"Write") ) // Here I save
           {
              StreamWriter sw = new StreamWriter(filename); 
                 sw.WriteLine(Mute.paused);//I have a Cube object which has Mute script and a"public static bool "paused" on it
                 Debug.Log("Save" + Mute.paused);
                 sw.Close(); // Save
           }
        }
 
 
 
               In Load script I tell it the value
 public class Load : MonoBehaviour {
     public bool isMusic;
 
     
     void Start () {
          StreamReader streamReader = new StreamReader("Data/Save/Position.sg");
         if(streamReader != null) {
           while (!streamReader.EndOfStream)
           {
                 isMusic = System.Convert.ToSingle(streamReader.ReadLine());// HERE'S AN ERROR
           }
             if(isMusic==false){
                 audio.Pause();
         }
         }
     }
 }
 
               It gives an error: /C#/Load.cs(10,33): error CS0029: Cannot implicitly convert type float' to bool' What to do? 
               Comment
              
 
               
              Your answer