Showing posts with label submit scores. Show all posts
Showing posts with label submit scores. Show all posts

Friday, January 18, 2013

Submit Scores and Points to Game Center in Unity3D

This simple script is how to submit scores and points to the Game Center from a Unity3D Game. People use the prime31 plugin, and pay the extra money, which dumbfounds me. Just do it yourself! I've done both JS and C# implementations of the same code... Here it goes in JavaScript:



#if UNITY_IPHONE
import UnityEngine.SocialPlatforms;
#endif

//These next two methods show the leaderboard

function DoLeaderboard () {
#if UNITY_IPHONE
Social.localUser.Authenticate (ProcessAuthentication);
#endif
}

function ProcessAuthentication (success: boolean) {
#if UNITY_IPHONE
    if (success) {
        Debug.Log ("Authentication successful");
    Social.CreateLeaderboard();
Social.CreateLeaderboard().id = "YourLeaderBoardID";
Social.ShowLeaderboardUI();
    }
    else
        Debug.Log ("Failed to authenticate");
#endif
}


//these next two methods report a score to the leaderboard

function reportScoreToBoard() {
#if UNITY_IPHONE
Social.localUser.Authenticate (ReportScore);
#endif
}


function ReportScore (success: boolean) {
#if UNITY_IPHONE
    if (success) {
        
        Debug.Log ("Authentication successful");
   
    Social.CreateLeaderboard();

Social.CreateLeaderboard().id = "YourLeaderBoardID";
Social.ReportScore(PlayerPrefs.GetInt("timeElapsed"),"YourLeaderBoardID",  function(result) {
        if (result)
            Debug.Log ("Successfully reported timeElapsed, Virgin:" + PlayerPrefs.GetInt("timeElapsed"));
        else
            Debug.Log ("Failed to report timeElapsed");});

//if you want uncomment below to show leaderboard!
//Social.ShowLeaderboardUI();
    }
    else
        Debug.Log ("Failed to authenticate");
        
 #endif
}



Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...