最后一个数据,如果不开 float,生命值会得到这么一个奇怪的数字:
float
3.72529e-07
这是浮点数运算的误差导致的。如果你执意要用 float,千万不能这么写:
if (health <= 0) break;
你需要:
if (health <= 0.01) break;