現在、unityで作ったゲームにiOSのGameCenterを実装しています。
実機でデバッグしてみたところ、認証成功してはいるのですが
ちゃんとスコアをloadできずスコアを0のまま送ってしまっています。
iTunesConnectの方では、スコアのフォーマットタイプは
Elpsed Time -To the Hundredth of a Second-で、
スクリプトにどう書けばよいか把握できておりません。
どなたか詳しい方ぜひともなんとかご助言をお願いします!!!
Test_ScoreReport.cs
lang
1using UnityEngine; 2using System.Collections; 3 4public class Test_ScoreReport : MonoBehaviour { 5 6 public int score1; 7 8 void Start(){ 9 ReportScore(score1, "leaderboardID"); // iTunes Connectで設定したleaderbordIDを入れる。 10 } 11 12 void ReportScore (long score, string leaderboardID) { 13 Debug.Log ("Reporting score " + score + " on leaderboard " + leaderboardID); 14 Social.ReportScore (score, leaderboardID, success => { 15 Debug.Log(success ? "スコア報告は成功しました。" : "スコア報告は失敗しました。"); 16 }); 17 } 18 19} 20
↑おそらくはここらへんをelpsed timeに合わせた形に変更しなければなりません。
また、元のスコアを僕の場合はfinishcontrollerで最新のスコアをcurrentRecord、今までで一番良いスコアをhistoricalRecordとして表しています。
FinishController.js
lang
1#pragma strict 2import UnityEngine.UI; 3//import NendUnityPlugin.AD; 4var currentRecord : UI.Text; 5var historicalRecord : UI.Text; 6var newRecord : UI.Image; 7private var prefix : String = "finish_"; 8// AudioClip. 9var seOnRestart : AudioClip; 10var seOnFanfare : AudioClip; 11function Awake(){ 12 newRecord.enabled = false; 13} 14function Start(){ 15 currentRecord.text = secondsToTimeFormat(StopWatch.referenceCurrentRecord); 16 historicalRecord.text = "Best Record " + secondsToTimeFormat(StopWatch.referenceHistoricalRecord); 17 if(StopWatch.isNewRecord){ 18 newRecord.enabled = true; 19 // 新記録の場合のファンファーレを鳴らす 20 audio.PlayOneShot(seOnFanfare); 21 }else{ 22 if((PlayerPrefs.GetInt(prefix + "PlayCount",0) == 2 || PlayerPrefs.GetInt(prefix + "PlayCount",0) % 10 == 0) && PlayerPrefs.GetString(prefix + "isReview","true") == "true"){ 23 StartCoroutine("recommendReview"); 24 }else{ 25 if(Mathf.Floor(Random.Range(0,2)) == 0){ 26 //interstecial 27 #if UNITY_IPHONE 28 NendAdInterstitial.Instance.Load(Define.nendiOSApiKey,Define.nendiOSSpotId); 29 #elif UNITY_ANDROID 30 NendAdInterstitial.Instance.Load(Define.nendAndroidApiKey,Define.nendAndroidSpotId); 31 #endif 32 StartCoroutine("coroutineInterstitialShow"); 33 } 34 } 35 } 36 PlayerPrefs.SetInt(prefix + "PlayCount",PlayerPrefs.GetInt(prefix + "PlayCount",0) + 1); 37} 38function onClickRestart(){ 39 StartCoroutine("coroutineRestart"); 40} 41function coroutineInterstitialShow(){ 42 yield WaitForSeconds(2.0); 43 NendAdInterstitial.Instance.Show(); 44} 45function coroutineRestart(){ 46 audio.Stop(); 47 audio.PlayOneShot(seOnRestart); 48 yield WaitForSeconds(1.3); 49 Application.LoadLevel("S1_Main"); 50} 51function secondsToTimeFormat(seconds : float){ 52 var mins : int = seconds / 60; 53 var t : float = seconds % 60.0; 54 var sens : int = t / 1.0; 55 t = t % 1.0; 56 var msens : int = t / 0.01; 57 return mins.ToString() + ":" + sens.ToString("D2") + ":" + msens.ToString("D2"); 58}
↑のおそらくはfunction Startのところと、function secondsToTimeFormatが関係しているかと思います。
直接的な解決方法でなくともよいのでご助言お願いいたします!
あなたの回答
tips
プレビュー