// attacks and deals damage to player when within attack range // and player is in front of an enemy at a certain angle void HandleAttack() { // Handles successful attack. attackTime += Time.deltaTime; if (attackTime > timeToDamage && !hasSwung) // When to deal damage based on animation { // calculates if enemy is facing player Vector3 facing = player.transform.position - transform.position; // gets dot product of unit vectors float dot = Vector3.Dot(facing.normalized, transform.forward); // attempts to attack even if won't hit // functioning as a sound cue to help time strafing AudioSource.PlayClipAtPoint(attackSound, transform.position); if (dot >= 0.8f) { // attack playerStats.ChangePlayerHealth(-attackDamage); } hasSwung = true; } if (attackTime > attackDuration) // Resets attack abilities when done { hasSwung = false; currentState = FSMStates.Chase; attackTime = 0; anim.SetInteger("ActiveState", 1); } }
private void OnConsume() { var item = EquippedItem as ConsumableItem; if (item.Consumptions > 0) { if (consumeSFX) { AudioSource.PlayClipAtPoint(consumeSFX, transform.position); } item.Consume(); PlayerStatistics playerStatistics = GetComponent <PlayerStatistics>(); playerStatistics.ChangePlayerHealth(item.Properties.HealthOnConsume); playerStatistics.ChangePlayerHunger(item.Properties.HungerOnConsume); playerStatistics.ChangePlayerRadiation(item.Properties.RadiationOnConsume); if (item.Consumptions == 0) { RemoveEquipment(); ItemCollector itemCollector = GetComponent <ItemCollector>(); itemCollector.RemoveFromInventory(item); } } }