Last active
August 29, 2015 14:11
-
-
Save sanxfxteam/2ea09339cf46374a5d36 to your computer and use it in GitHub Desktop.
Implements basic scoring example for Unity of GameJolt API and API Helper by Loic Teixiera @loicteixeira
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// 0. Download this file as GJBehavior.cs | |
// 1. Attach this script to a new GameObject and rename it to "GJAPI". | |
// 2. Edit game and api key | |
// 3. To post score from anywhere | |
// if (GameObject.Find("GJAPI").GetComponent<GJBehavior>().CanAddScore) | |
// GJAPI.Scores.Add(score.ToString() + " points", (uint)score, 14669, ""); | |
public class GJBehavior : MonoBehaviour { | |
// Use this for initialization | |
void Awake () { | |
DontDestroyOnLoad(gameObject); | |
GJAPI.Init(14443, // Test Value, Replace with yours | |
"41927b93329fe63a5e1e7c3f67df62a9", // Test Value, Replace with yours | |
true, | |
1); | |
GJAPI.Users.VerifyCallback += OnUserVerified; | |
GJAPI.Scores.AddCallback += OnScoreAdded; | |
GJAPIHelper.Users.GetFromWeb(OnGetFromWeb); | |
} | |
void OnGetFromWeb (string name, string token) | |
{ | |
if (!(name != null && token != null)) | |
return; | |
GJAPI.Users.Verify(name, token); | |
} | |
void OnUserVerified(bool success) | |
{ | |
can_add_score = success; | |
} | |
bool can_add_score = false; | |
public bool CanAddScore { get {return can_add_score; } } | |
void OnScoreAdded(bool success) | |
{ | |
if (success) { | |
Debug.Log ( "Score Added!" ); | |
} | |
else { | |
Debug.Log ( "Score Added Failed!" ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment