Unity3d-如何检查我的角色是否在空中停留了 2 秒?

Unity3d- How can I check if my character is in air for 2 seconds?

我正在使用光线投射来确定我的播放器是否在空中

如何检查我的角色在切换到另一个状态之前是否在空中停留了 5 秒

添加两个新变量。

bool InAir;
float InAirTimer;

进行光线投射时,如果您在空中,则将 InAir 设置为 true,否则为 false。然后在更新中,这样做:

if (inAir) { inAirTimer += Time.deltaTime; }
else { inAirTimer = 0; }
if (inAirTimer >= 5) { /* Here is where you do something */ }