在 Google Play Games in Unity 中增加成就时出现问题
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
}
我有一项成就会随着生存时间的增加而增加。 我用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
}