- Home /
Help with Kongregate API?
Hi! I'm new to Unity. I upload my games to www.kongregate.com, and I'm trying to upload the score from the game to the website. The guide to the API from the website is very unclear to a beginner and I cannot understand it. I am wondering if anyone has used it before or is experienced and can explain how to script this. Document for using the API with unity3d: http://www.kongregate.com/developer_center/docs/en/using-the-api-with-unity3d Any example would be great. Here is the script for my player (which handles the game's score). I want to pass it through to another scene with a script attached to the Main Camera that handles loading the API and submitting the score. Thank you!!! //Player Script
//Inspector Variable
var tagName : String; //allow the designer to setup a tag
var rayDistance : float = 0; //length of the ray for our raycast
var score : int = 0; //score for our player
var gameTime : float = 20.0; //the amount of time the game will last
var requiredScore : int = 20; //the amount of score required to win the game
//Private Variables
//Called once
function Start()
{
InvokeRepeating("CountDown", 1.0, 1.0);
}
//Update is called every frame
function Update ()
{
//use mouse button to select on game objects in the scene
if(Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit, 100.0))
{
if(hit.transform.tag == "enemy")
{
//var position = Vector3(Random.Range(-4,4), Random.Range(-4,4), 0);
//hit.transform.position = position;
var enemyScript = hit.transform.GetComponent(scriptActorEnemy);
enemyScript.numberOfClicks -= 1; //Reduce the number each click
if(enemyScript.numberOfClicks == 0) //Check that the object is destroyed (0 clicks)
{
score += enemyScript.enemyPoints; //Add points to our overall score
}
}
}
}
}
function CountDown()
{
if(--gameTime == 0) //subtract from gametime
{
CancelInvoke("CountDown"); //cancel the countdown
//yield WaitForSeconds(3.0); //amount of time before loading next scene
if (score >= requiredScore)
{
Application.LoadLevel("sceneScreenWin");
}
else
{
Application.LoadLevel("sceneScreenLose");
}
}
}
function OnGUI()
{
GUI.Label(Rect(10, 10, 100, 20), "Socre: " + score);
GUI.Label(Rect(10, 25, 100, 35), "Time: " + gameTime);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Cannot initialise Kong API 2 Answers
How do I implement the Kongregate api 4 Answers
Using the Kongregate API 1 Answer
How to make a selection system? 1 Answer