Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

GameCenter How to Track Score?

$
0
0
Hi Jeremy here, and I have my script (script below) that activates gamecenter and adds the game to gamecenter successfully and all that but I have not been able to figure out how to track the score of of my player and make it show up on the leaderboards in gamecenter? Its a simple high score based game like flappy bird but I can't find any solid source on how to do it? Any help is greatly appreciated! /// TnT_GameCenter /// /// all gamecenter related sourcecode and tools /// public class TnT_GameCenter : MonoBehaviour { // ------------------------------- // parameter // ------------------------------- // ------------------------------- // private members // ------------------------------- private bool isLoggingIn = false; // true if logging in, false while not private bool loggedIn = false; // stores if the user is logged into the game center // ------------------------------- // standard monobehaviour // ------------------------------- /// /// Start this instance /// starts login into gamecenter if not disabled /// void Start () { isLoggedIn (); login(); GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true); } // ------------------------------- // public api // ------------------------------- /// /// Login this user /// public void login( ) { // login only if gamecenter is enabled if ( PlayerPrefs.GetInt ( "GameCenter", 1 ) == 0 ) return; // now log in Debug.Log ( "Logging into Gamecenter" ); if ( loggedIn == true ) return; if ( isLoggingIn == true ) return; isLoggingIn = true; Social.localUser.Authenticate (ProcessAuthentication); } /// /// checks if user is logged in /// /// /// Ttrue if logged in /// public bool isLoggedIn ( ) { Debug.Log ( "USER : " + Social.localUser ); return loggedIn; } /// /// Saves the game score at the leaderboard of gamecenter /// /// /// Ship to save /// /// /// Score to save /// public void saveGameScore ( string ship, int score ) { // only if gamecenter is enabled if ( !isLoggedIn () ) return; // report global score Social.ReportScore ( score, "grp.Best", ScoreSubmitted ); // report ship based score if ( ship == "SpaceCab" ) { Social.ReportScore ( score, "grp.SpaceCab", ScoreSubmitted ); return; } if ( ship == "BA75" ) { Social.ReportScore ( score, "grp.BA75", ScoreSubmitted ); return; } if ( ship == "DartX" ) { Social.ReportScore ( score, "grp.DartX", ScoreSubmitted ); return; } if ( ship == "SR1" ) { Social.ReportScore ( score, "grp.NovaSR1", ScoreSubmitted ); return; } if ( ship == "CobraMKIII" ) { Social.ReportScore ( score, "grp.CobraMKIII", ScoreSubmitted ); return; } if ( ship == "DMC" ) { Social.ReportScore ( score, "grp.DMC", ScoreSubmitted ); return; } Debug.LogError ( "Unknown ship " + ship ); } /// /// Reports the progress of an achievement /// public void reportProgress ( string achievementId, double progress ) { Debug.Log ( "REPORTING ACHIEVEMENT : " + achievementId ); if ( !isLoggedIn () ) return; Social.ReportProgress ( achievementId, progress, AchievementSubmitted ); } // ------------------------------- // internal tool functions // ------------------------------- /// /// called when the gamecenter login is finished /// /// /// tells if the authentication was successfull /// void ProcessAuthentication (bool success) { isLoggingIn = false; if (success) { Debug.Log ("Authenticated, checking achievements"); this.loggedIn = true; Social.LoadAchievements ( LoadedAchievements ); } else { Debug.Log ("Failed to authenticate"); this.loggedIn = false; } isLoggedIn(); } /// /// callback for reportScore /// /// /// Success true if submission of score succeeded /// void ScoreSubmitted ( bool success ) { if ( !success ) Debug.LogWarning ( "Failed to submit score" ); else Debug.Log ( "submitted score succesfull" ); } /// /// callback for reportScore /// void AchievementSubmitted ( bool success ) { if ( !success ) Debug.LogWarning ( "Failed to submit achievement" ); else Debug.Log ( "Submitted achievement successfull" ); } /// /// callback for achievements loaded /// void LoadedAchievements ( IAchievement[] achievements ) { if (achievements.Length == 0) Debug.Log ( "No Achievments found" ); else Debug.Log ("Got " + achievements.Length + " achievements"); } }

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>