Timer-Based Attack System
I'm trying to develop an attack system which requires the user to press a button at a critical point in order to deal maximum damage. By clicking the attack button, a UI element is displayed and a float begins moving from 0, all the way to 1, and then to 0 again, and the player needs to attack when the value is 1 in order to deal maximum damage, otherwise the damage value is lowered based on a multiplier. So far I have the attack function dealing a random damage value based on two numbers - could someone please help me change it to what I've described? I experimented with timers and co-routines but I'm not too experienced with them. Any help would be amazing :)
Attack function (specifically the "double dmgValue" section that is relevant):
public void Attack() {
double dmgValue = UnityEngine.Random.Range(Strength.Value * 0.9f, Strength.Value * 1.1f);
if (PlayerMovement.EnemyCurHealth > dmgValue) {
CurHealth -= PlayerMovement.EnemyDamage;
Debug.Log("Enemy has just attacked you for " + PlayerMovement.EnemyDamage + " points of damage!");
}
PlayerMovement.EnemyCurHealth -= Convert.ToInt32(dmgValue);
Debug.Log("Dead: " + isDead);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613002458im_/https://answers.unity.com/themes/thub/images/avi.jpg)