- Home /
How to make a high score file for webGL?
hello, i have made a simple mini-game with a high score system in it. i have built it for web gl and put it up on my website but it doesn't seem to save the high score file to the server. could you tell me where it might be saving and how to make it save to a file on the server so people can see others high score?
here is the code:
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
... ... ...
public void Save_Score(){
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create ("Score.dat");
PlayerData data = new PlayerData ();
data.High_Score = High_Score;
bf.Serialize (file, data);
file.Close();
}
public void Load_Score(){
if (File.Exists ("Score.dat")) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open("Score.dat" , FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
High_Score = data.High_Score;
}
}
}
[Serializable]
class PlayerData
{
public int High_Score;
}
Comment
Answer by T-ruth · Sep 04, 2020 at 08:08 AM
Having the same question. I was so hopeful when I saw you asked it, but it seems like there never was any answer.
Your answer
Follow this Question
Related Questions
How can I bypass CORS with Unity WebGL? 3 Answers
Itch.io webgl not uploading properly 1 Answer
Upload a image from PC memory to WebGL app 0 Answers
Scale WebGL cavas to browser window size 0 Answers
Realtime multiplayer over web server 0 Answers