Unity How to Use Kongregate API

Create a empty GameObject call MyUnityObject and attach the folowing script.

KongregateAPI.js
var isKongregate = false;
var userId = 0;
var username = "Guest";
var gameAuthToken = "";
 
// callback
function OnKongregateAPILoaded(userInfoString : String){
	isKongregate = true;
 
	var params = userInfoString.Split("|"[0]);
	userId = parseInt(params[0]);
	username = params[1];
	gameAuthToken = params[2];
}
 
function Awake(){
	// init api the call OnKongregateAPILoaded
	Application.ExternalEval(
		"if(typeof(kongregateUnitySupport) != 'undefined'){" +
		" kongregateUnitySupport.initAPI('MyUnityObject', 'OnKongregateAPILoaded');" +
		"};"
	);
}

Now you can communicate with the API in your code. For example add a HighScore statistic.

Test.cs
Application.ExternalCall("kongregate.stats.submit", "HighScore", GameManager.SCORE);
Navigation
Print/export
Toolbox