private void ShootCurrentEnemy() { if (currentEnemy != null) { currentState = FriendlyAIStates.Attacking; currentEnemy.position = new Vector3(currentEnemy.position.x, transform.position.y, currentEnemy.position.z); transform.LookAt(currentEnemy); } else { FindNextEnemy(); } RaycastHit hit; Debug.DrawRay(transform.position, transform.forward * 1000, Color.red); if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity) && timer > timeBetweenAttacks) { timer = 0; IDamageable damageableObject = hit.collider.GetComponent <IDamageable>(); if (damageableObject != null) { damageableObject.TakeDamage(attackPower); } } else { timer += Time.deltaTime; } }
void Start() { maxhealth = health; friendlyAI = gameObject; enemies = new List <GameObject>(); navMeshAgent = GetComponent <NavMeshAgent>(); currentState = FriendlyAIStates.Idle; }
protected override void Die() { currentState = FriendlyAIStates.Dead; }