【发布时间】:2019-10-09 20:39:15
【问题描述】:
我需要积累一定的能量,在鼠标松开的时候释放。现在,当能级达到最大值时,能级设置为 0,函数从头开始重新开始累积,创建一个循环。
IEnumerator AttackCharge()
{
while (true)
{
if (Input.GetMouseButton(1) && energyLevel < energyMax)
{
energyLevel += 1;
yield return new WaitForSeconds(playRate);
}
if (Input.GetMouseButtonUp(1))
{
if (energyLevel == energyMax)
{
FxPlayerAttack.Stop();
FxPlayerAttack.Play();
shootSound.PlayOneShot(attackSound);
GetComponentInChildren<ParticleCollision>().attackValue = energyLevel;
yield return new WaitForSeconds(2);
energyLevel = 0;
GetComponentInChildren<ParticleCollision>().attackValue = energyLevel;
}
if (energyLevel < energyMax)
{
yield return new WaitForSeconds(2);
energyLevel = 0;
}
}
yield return null;
}
}
我需要在按住按钮的同时积累能量。当按钮向上时,能量应该在充电阶段达到最大值时释放,能量水平应该回到0并且停止累积,直到再次按下按钮。
【问题讨论】:
-
playRate是什么? -
playRate这是一个浮点数,用于确定执行声音、粒子系统等的增量时间。