Exemple #1
0
    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;
        }
    }
Exemple #2
0
 void Start()
 {
     maxhealth    = health;
     friendlyAI   = gameObject;
     enemies      = new List <GameObject>();
     navMeshAgent = GetComponent <NavMeshAgent>();
     currentState = FriendlyAIStates.Idle;
 }
Exemple #3
0
 protected override void Die()
 {
     currentState = FriendlyAIStates.Dead;
 }