/// <summary> /// Attempts to attack. /// The Player can only attack every timeBetweenAttacks. /// There is 12.5% chance that the Player will miss. /// The damage is applied to target Enemy health. /// </summary> private void Attack() { if (Input.GetMouseButtonDown(0) && (Time.time - timeSinceLastAttack >= timeBetweenAttacks)) // Checks if the button was clicked { // and if it is the time to attack Debug.Log("Attempt to attack"); timeSinceLastAttack = Time.time; // TODO: Change animation to attack GameObject enemy = EnemyClicked(); // Get anything that was clicked on if (enemy == null) { return; // Returns if the enemy is null } if (enemy.CompareTag("Enemy") && Vector3.Distance(enemy.transform.position, transform.position) <= range) // Checks if the target is an Enemy and is in range { EnemyHealth enemyHealth = enemy.GetComponent <EnemyHealth>(); int missValue = Random.Range(0, 8); if (missValue != 0) // Checks if the attack missed { float damage = baseDamage + Mathf.Round(Random.Range(3.0f, 7.0f)); // Calculate the damage enemyHealth.ChangeHealthPoints(-damage); playerIntensity.Increase(intensityIncrease); // Increase intensity when hitting an Enemy } else { Debug.Log("Player missed."); } } } }