Search Unity

Sending my highscore to a iOS GameCenter Leaderboard

Discussion in 'Scripting' started by DarkNeo, Nov 21, 2014.

  1. DarkNeo

    DarkNeo

    Joined:
    Apr 27, 2014
    Posts:
    53
    Hi there,

    So I have set up my leader board in iTunes Connect, my game logs in perfect with my sandbox test account into Game Center, however no scores are being sent to the leader board, I have heard that this process can be slow and can take a while for the sandbox test account to update the scores on the leader board it's been 4 hours now and still nothing. So I am guessing the problem would be with the code.

    I am using this for my code

    Code (JavaScript):
    1.  
    2. #if UNITY_IPHONE
    3. import UnityEngine.SocialPlatforms;
    4. #endif
    5.  
    6.  
    7. function Update ()
    8. {
    9.     guiText.text = "Highscore : " + PlayerPrefs.GetInt("score");
    10. }
    11.  
    12. //These next two methods show the leaderboard
    13.  
    14. function DoLeaderboard () {
    15. #if UNITY_IPHONE
    16. Social.localUser.Authenticate (ProcessAuthentication);
    17. #endif
    18. }
    19.  
    20. function ProcessAuthentication (success: boolean) {
    21. #if UNITY_IPHONE
    22.     if (success) {
    23.         Debug.Log ("Authentication successful");
    24.      Social.CreateLeaderboard();
    25.   Social.CreateLeaderboard().id = "com.MitchPerry.LightSpeed.Highscore";
    26.   Social.ShowLeaderboardUI();
    27.     }
    28.     else
    29.         Debug.Log ("Failed to authenticate");
    30. #endif
    31. }
    32.  
    33.  
    34. //these next two methods report a score to the leaderboard
    35.  
    36. function reportScoreToBoard() {
    37. #if UNITY_IPHONE
    38. Social.localUser.Authenticate (ReportScore);
    39. #endif
    40. }
    41.  
    42.  
    43. function ReportScore (success: boolean) {
    44. #if UNITY_IPHONE
    45.     if (success) {
    46.      
    47.         Debug.Log ("Authentication successful");
    48.    
    49.      Social.CreateLeaderboard();
    50. Social.CreateLeaderboard().id = "com.MitchPerry.LightSpeed.Highscore";
    51. Social.ReportScore(PlayerPrefs.GetInt("score"),"com.MitchPerry.LightSpeed.Highscore",  function(result) {
    52.         if (result)
    53.                Debug.Log ("Successfully reported score, Virgin:" + PlayerPrefs.GetInt("score"));
    54.            else
    55.                Debug.Log ("Failed to report score");});
    56.  
    57. //if you want uncomment below to show leaderboard!
    58. //Social.ShowLeaderboardUI();
    59.     }
    60.     else
    61.         Debug.Log ("Failed to authenticate");
    62.      
    63. #endif
    64. }
    65.  
    Unity is not giving me any errors back so I don't know if that is a good thing or not.

    I tried using the documentation code for submitting scores to a leader board, however I am having no luck with that either that does not detect my High score script.

    I bought a plug in for to get the leader board to work and it's written in C Sharp and will not work correctly with my Java script high scoring.

    Any help would be greatly appreciated! Thank you :)
     
    Last edited: Nov 21, 2014
  2. DarkNeo

    DarkNeo

    Joined:
    Apr 27, 2014
    Posts:
    53
    Ended up calling

    Code (JavaScript):
    1. reportScoreToBoard();
    When my character dies and that then enabled the score to be sent. :)