Simple leaderboard with google forms and sheets


Step 1: Create a Google Form:

https://docs.google.com/forms/
Create a form with two questions: "Name" and "Score"


Step 2: Link with a spreadsheet:

Go to the Responses tab, click on the kebab menu and select "Select Response Destination"




Choose "Create a new spreadsheet"



Set up the spreadsheet with a simple no-spaced name, then create a new sheet and move it to the left so it's the "main" sheet.




Add this function to the A1 cell of the new sheet. It will copy the contents of the other sheet and sort by score. The "FALSE is for descending order.


Step 3: Post to form from game

Create a prefilled link, and then change "viewForm?" to "formResponse?" and add "&submit=Submit" to the end




Step 4: Use the link in Unity

In a Unity C# script create a function like this:


    IEnumerator PostScore(string name, string score)
    {
        string url = $"https://docs.google.com/forms/d/e/1FAIpQLSfhiYPTlLFX6nX9POx5-eD1cUN30H7xIOF1odJnwOrwoxkvsg/formResponse?usp=pp_url&entry.600859052={name}&entry.508281831={score}&submit=Submit"
        UnityWebRequest www = UnityWebRequest.Post(url, "");
        yield return www.SendWebRequest();
    }
And call it like so:

    StartCoroutine(PostScore("some name", "123"));

It'll post a new form response with the passed in name and score. From there you can navigate the user to the spreadsheet. You'll want to modify the share settings in the spreadsheet so it can be viewed only with a link.

Files

web.zip Play in browser
Apr 24, 2021

Comments

Log in with itch.io to leave a comment.

this is really cool, i've never thought about doing a leaderboard with a google form!

Thanks! I don't know if I'd use it in any serious projects, but it worked out really well for a a simple and free solution. The next step would be to read the spreadsheet data natively in Unity. Maybe one of these days I'll get around to it.