GUI Button does not work from exe file

In my game I am showing a button at top. When the user clicks it, it was supposed to pops up a game over screen. Now this button works fine when I play it in unity or even play it using the File → Build & Run.

But the problem occurs when I just build the game and try playing it using my game.exe file. The button is still there, but when I click the button it does nothing. Btw, the game over screen was supposed to show up after hitting x button on keyboard and that’s not working either.

I am creating the Game Over Screen in OnGUI using GUI functions.

EDIT:

void StopGame()
    	{
    	        AppendString(PlayerScript.GData);
    		currentMode = GAME_MODE.STOP;
    		Time.timeScale = 0;
    	}
    void AppendString(string GameData)
    	{
    		TextWriter io; 
    		string File = "data";
    		if(System.IO.File.Exists(File+".csv"))
    		{
    			io = new StreamWriter("Assets/Resources/"+File+".csv");
    			io.WriteLine(GameData);
    			io.Close();
    			return;
    		}
    		else
    		{
    			System.IO.File.Create(File+".csv");
    			io = new StreamWriter("Assets/Resources/"+File+".csv");
    			io.WriteLine(GameData);
    			io.Close();
    			return;
    		}
    	}

But the Exit(x) button is not working.

Could you post the relevant code?

Are you getting any error message when running from the Editor?

did you add the game over Scene to build settings?

@thef1chesser i added some more code

@raimon.massanet: no there's no error msg @fornoreason1000: game over scene is not a separate scene, may be this will clarify it: i'm making a GUI box with some text and button in it when user clicks Exit(x) button

1 Answer

1

Try In line 20: mention the file path as Application.persistentDataPath, it seems to have problem in finding path

yep that was the problem, is there any way I can change this path?

System.IO.File.Create(Application. persistentDataPath+"/"+File+".csv")

sorry i wasn't clear enough, I am using Application.persistentDataPath to fix my problem, but that creates the file in a very weird place. I wanted to know if I could change the path so that say the file will be on my Desktop

I hope that some one is still viewing this thread cause I have a question. How secure is the values written? I mean, can the user go in and edit it since it's technically a save on his account?