gpt4 book ai didi

c# - 检查 float Against array 但跳过值

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:01 25 4
gpt4 key购买 nike

我有这个脚本,它从时间开始对固定值执行 reflectionProbe.RenderProbe(),问题是有时它会跳过数组中的一个值。我做错了什么?

http://i.imgur.com/9NwVq7X.png

public float secondsInFullDay = 120f;
private float[] floatDay = new float[40] {
0, 250, 500, 750, 1000, 1250, 1500, 1750, 2000,
2250, 2500, 2750, 3000, 3250, 3500, 3750, 4000,
4250, 4500, 4750, 5000, 5250, 5500, 5750, 6000,
6250, 6500, 6750, 7000, 7250, 7500, 7750, 8000,
8250, 8500, 8750, 9000, 9250, 9500, 9750};

[Range(0,1)]
public float currentTimeOfDay = 0f;

public float TimeOfDay = 0f;
public float timeMultiplier = 1f;

void Update() {
currentTimeOfDay += (Time.deltaTime / secondsInFullDay) * timeMultiplier;

if (currentTimeOfDay >= 1) {
currentTimeOfDay = 0;
}

TimeOfDay = currentTimeOfDay * 10000 / timeMultiplier;
TimeOfDay = Mathf.Round(TimeOfDay);


foreach (float x in floatDay){
float y = x / timeMultiplier;
if (TimeOfDay == y){
reflectionProbe.RenderProbe();
Debug.Log ("refresh probe " + y);
}
}
}

最佳答案

if(Mathf.Approximately(TimeOfDay, y))
{
//Do something
}

关于c# - 检查 float Against array 但跳过值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30775528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com