C# 倒计时计时器在0时不会触发任何东西

C# 倒计时计时器在0时不会触发任何东西,c#,unity3d,C#,Unity3d,我已经为我的游戏制作了这个倒计时计时器,我希望它在倒计时计时器达到0时激活UI,但我不知道如何实现这一点 这是我的密码 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class score : MonoBehaviour { public Text ScoreText; public float scoreAmount;

我已经为我的游戏制作了这个倒计时计时器,我希望它在倒计时计时器达到0时激活UI,但我不知道如何实现这一点

这是我的密码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class score : MonoBehaviour
{

public Text ScoreText;

public float scoreAmount;

public int startscore;

private float pointIncreasedPerSecond;

public float scoreMultiplier;

public GameManager gameManager;

void Start()
{
    scoreAmount = startscore;
    pointIncreasedPerSecond = 1f;
}
void Update()
{
    ScoreText.text = scoreAmount.ToString("0");
    scoreAmount += pointIncreasedPerSecond * scoreMultiplier * Time.deltaTime;

    if(scoreAmount == 0)
    {
        gameManager.victory();
    }
}
}
您应该这样做:

void Start() {
    scoreAmount = the value you want it to be at start
}


void Update() {
    scoreAmount -= Time.deltaTime;
    if (scoreAmount <= 0) {
        gameManager.victory();
    }

}
void Start(){
scoreAmount=您希望它在开始时的值
}
无效更新(){
scoreAmount-=Time.deltaTime;

如果(scoreAmountOk,首先我假设你的计数器以负值开始,应该增加到0,对吗

因此,
scoreAmount==0
不能发生,因为您使用的是浮点数

当使用浮动时(尤其是使用Time.deltaTime),几乎没有机会获得偶数。(在此处检查
scoreAmount>0


对于将来的问题,请使用标签并告诉其他人您正在使用Unity引擎。没有任何普通程序员会知道每帧调用
Update()

您没有创建倒计时计时器,您创建了一个包含一些数据的类。这里没有任何“倒计时”您好@Edmund。可能是因为scoreAmount不完全是0,而是接近0。您使用的是浮点值。您应该设置触发gameManager.victory();。类似于if(scoreAmount)的容差。这是否回答了您的问题?这是否回答了您的问题?