This is currently used in my Escape Drill game for Ludum Dare #29, but missing a lot of features.
- Copy the contents of the
newgroundsfolder to your Unity project's "Scripts" folder
- Anywhere in your code (e.g. your
Maingame class), connect to the API:
- Whenever you need to submit statistics, do:
Newgrounds.API.PostScore("High Score (level 1)", 1000); Newgrounds.API.PostScore("Tanks Destroyed", 10);
Newgrounds.API.Connect(string apiId, string encriptionKey)(Static): Connects to the API. You need to do this before anything is posted. You can find the API id and encryption key values in the API Tools section of your project.
Newgrounds.API.PostScore(string name, int value)(Static): submit a score to the Newgrounds API. The
nameis not an id, but rather how the score is represented in the website.
connectionUserName: current user name. Read-only.
connectionUserId: id of the current user. Read-only.
connectionSessionId: a long hash with the id of the current session. Read-only.
The API will not work inside the editor by default. This is because it needs some kind of session ID that is passed by the website when the game is ran. However, the API does detect when you're running inside the editor and attempt to use a placeholder URL. To replace this placeholder URL with a real URL, go to your game's page, find the URL of the iframe used to host it, and replace the
setContainerURLStatic() call in line 45 of API.cs with this url. It will look like this:
- A lot is missing. Actually it only posts high scores right now.