繁体   English   中英

在 Unity 中增加 Google Play 游戏成就的问题

[英]Problem increasing an achievement in Google Play Games in Unity

我的成就会随着幸存的时间而增加。 我用 Time.time 计算存活时间。 当我死时,我会使用 Time.time 值增加成就以增加存活秒数,但它增加的次数远远超过应有的数值。 我的代码:

using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;

    public class Timer : MonoBehaviour
    {
        private float StartTime;
        public static float TimerControl;

        void Start()
        {
            StartTime = Time.time;
        }

        void Update()
        {
            //The player is alive
            if (PlayerController.dead == false)
            {
                TimerControl = Time.time - StartTime;
            }

            //The player is dead
            if (PlayerController.dead == true)
            {
                PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_survivor, (int)(TimerControl), (bool success) => {

                });
            }
        }
    }

成就增加的生存时间远远大于应有的时间。

有什么建议吗? 谢谢!

试试这个,如果它不起作用,请告诉我调试给你什么。

using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
public class Timer : MonoBehaviour
{
    void Update()
    {
        //The player is dead
        if (PlayerController.dead == true)
        {
        Debug.Log("Time : " + Time.time);
        PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_survivor, (int)(Time.time), (bool success) => {
            });
        }
    }
}

编辑:好的,我想我知道你在更新循环中增加它发生了什么,所以你必须多次实施它

bool recorded = false;
// ...
        //The player is dead
        if (PlayerController.dead == true && !recorded)
        {
            PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_survivor, (int)(TimerControl), (bool success) => {

            });
        recorded = true;
        }

您是否尝试过使用Time.deltaTime 或者将该代码块放在 -

void FixedUpdate() { 
    //code 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM