示例#1
0
    /// <summary>
    /// Base state in which enemy "wanders" around, looking for the player
    /// </summary>
    private void IdleState()
    {
        enemyNavMeshAgent.speed            = enemyStats.WalkingSpeed; // Set up the NavMeshAgent
        enemyNavMeshAgent.stoppingDistance = 0.0f;                    // Distance to stop from the destination

        if (Time.time - wanderingTime >= 5.0f)                        // Checks if it's the time to take a new destination to walk to
        {
            wanderingTime = Time.time;
            SetDestination(RandomPosition());
        }

        if (CalculateDistance() < enemyStats.ViewDistance) // Checks if it "sees" the Player
        {
            if (enemyHealth.GetHealthPoints() <= 15.0f)
            {
                currentState = State.Flee; // Change state to Flee
            }
            else
            {
                currentState = State.Chase; // Change state to Chase

                playerIntensity.Increase(intensityIncrease);
            }

            Debug.Log("The current state is: " + currentState);
        }
    }
示例#2
0
    /// <summary>
    /// Modifies the enemy health points by the parameter.
    /// If an amount must be substracted then the parameter must be negative.
    /// </summary>
    /// <param name="modifier"></param>
    public void ChangeHealthPoints(float modifier)
    {
        enemyStats.EnemyHealthPoints += modifier;
        Debug.Log("Enemy health: " + enemyStats.EnemyHealthPoints);

        if (enemyStats.EnemyHealthPoints <= 0)               // Checks if the Enemy is still alive
        {
            gameObject.SetActive(false);                     // If not then deactivate the enemy
            if (!transform.parent.name.Equals("AIDirector")) // Checks if it is a child of AI Director
            {
                transform.parent = transform.parent.parent;  // If not then change parent to the AI Director
                transform.parent.gameObject.GetComponent <AIDirector>().ActiveEnemies--;
            }

            playerIntensity.Increase(intensityIncrease);
        }
    }
示例#3
0
    /// <summary>
    /// This method attempts to damage the Player.
    /// There is 25% that the Enemy will miss.
    /// If not then the value is substracted from Player's health.
    /// </summary>
    private void Attack()
    {
        int missValue = Random.Range(0, 4);

        if (missValue != 0)                                                                           // Checks if the Enemy missed
        {
            float damage = enemyStats.BaseDamage + Mathf.Round(UnityEngine.Random.Range(1.0f, 5.0f)); // Determines the total damage by adding a random value to the base

            playerHealth.ChangeHealthPoints(-damage);                                                 // Modifies the Player's health by the damage
            Debug.Log(gameObject.name + " hit the player for " + damage + " damage.");

            playerIntensity.Increase(intensityIncrease); // Increase Player's intensity
        }
        else
        {
            Debug.Log(gameObject.name + " missed.");
        }
    }
    /// <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.");
                }
            }
        }
    }