Try it:
#pragma strict
static var isKongregate = false;
var userId = 0;
var username = “?”;
var gameAuthToken = "";
// Begin the API loading process if it is available
function Awake ()
{
if (isKongregate) return;
DontDestroyOnLoad (transform.gameObject);
username = “Guest”;
Application.ExternalEval(“if(typeof(kongregateUnitySupport) != ‘undefined’){kongregateUnitySupport.initAPI(‘KongregateMonitor’, ‘OnKongregateAPILoaded’);}”);
// Register a sign in handler to let us know if the user signs in to Kongregate. Notice how we are using the
// Javascript API along with Application.ExternalEval, and then calling back into our app using SendMessage.
// We deliver the new user information as a simple pipe-delimited string, which we can easily parse using String.Split.
Application.ExternalEval(“kongregate.services.addEventListener(‘login’, function(){var services = kongregate.services;var params=[services.getUserId(), services.getUsername(), services.getGameAuthToken()].join(‘|’);kongregateUnitySupport.getUnityObject().SendMessage(‘KongregateMonitor’, ‘OnKongregateUserSignedIn’, params);”);
}
function OnKongregateAPILoaded(userInfoString : String)
{
isKongregate = true;
var params = userInfoString.Split(“|”0);
userId = parseInt(params0);
username = params1;
gameAuthToken = params2;
}
// Called when the Kongregate user signs in, parse the tokenized user-info string that we generate below using Javascript.
function OnKongregateUserSignedIn(userInfoString : String)
{
var params = userInfoString.Split(“|”0);
userId = parseInt(params0);
username = params1;
gameAuthToken = params2;
}
static function submitScoreWaves(value:int)
{
if (isKongregate)
{
Application.ExternalCall(“kongregate.stats.submit”, “waves.survival”, value);
}
}
function OnGUI()
{
GUI.Box(Rect(0,400,200,30), userId + " – " + username );
}
|