您实际上不需要委托的返回值。你也不需要Enemies
因为无论如何你都不会在例程中使用它。
这当然还是不如ref
参数是,但你可以简单地使用像这样的回调
delegate void Stat(float newValue);
private IEnumerator EnemyStatModify(float duration, float percent, float currentValue, Stat onUpdated)
//or
//private IEnumerator EnemyStatModify(float duration, float percent, float stat, Action<float> onUpdated)
{
onUpdated?.Invoke(currentValue * (1 - percent));
yield return new WaitForSeconds(duration);
onUpdated?.Invoke(currentValue);
}
并称之为
StartCoroutine(EnemyStatModify(state.duration, state.timeBtwHits, enemy.speed, (newValue) =>
{
enemy.speed = newValue;
}));
StartCoroutine(EnemyStatModify(state.duration, state.timeBtwHits, enemy.damage, (newValue) =>
{
enemy.damage = newValue;
});
而不是Stat
你也可以只使用Action<float>