我正在用 Unity 制作一款回合制 RPG,我有一个滑块,当玩家攻击时会弹出。A 沿着滑块向下移动,玩家将滑块移到中心越近并按下 Z,它造成的伤害就越大。然而,出于某种原因,它不是一个简单的输入,你要么猛击 Z,要么它根本不会接受输入。
代码如下:
void DamageGauge(int target, float power, bool special, string status, string name)
{
int t = target;
float p = power;
bool s = special;
string st = status;
string n = name;
meterOpen = true;
slashSlider.gameObject.SetActive(true);
slashSlider.value = 0;
StartCoroutine(DamageSliderTick(t, p, s, st, n));
}
// ReSharper disable Unity.PerformanceAnalysis
public IEnumerator DamageSliderTick(int target, float power, bool special, string status, string name)
{
bool press = false;
int t = target;
float p = power;
bool s = special;
string st = status;
string n = name;
BattleChar sTarget = activeBattlers[t];
for (int i = 0; i < 51; i++)
{
yield return new WaitForSeconds(.01f);
slashSlider.value += 4;
if (Input.GetKeyDown(KeyCode.Z) || i == 50)
{
float v = slashSlider.value;
if(i != 50)
{
switch (v)
{
case < 20:
DealDamage(t, p, .5f, s, st, n);
break;
case < 50:
DealDamage(t, p, .8f, s, st, n);
break;
case < 85:
DealDamage(t, p, 1, s, st, n);
break;
case < 97:
DealDamage(t, p, 1.4f, s, st, n);
break;
case < 132:
DealDamage(t, p, 1, s, st, n);
break;
case < 170:
DealDamage(t, p, .8f, s, st, n);
break;
case < 200:
DealDamage(t, p, .5f, s, st, n);
break;
}
} else
{
DealDamage(t, p, .5f, s, st, n);
}
slashSlider.gameObject.SetActive(false);
slashSlider.value = 0;
if (activeBattlers[t].currentHP <= 0)
{
RewardDialog.instance.xpPool += sTarget.xpWorth;
RewardDialog.instance.moneyPool += sTarget.dollarWorth;
if (sTarget.itemDrop[0] != null)
{
RewardDialog.instance.ShuffleItems(sTarget.itemDrop);
}
}
UpdateStatus(t);
NextTurn();
break;
}
}
}