예제 #1
0
    void Update()
    {
        // if the enemy has taken damage than play the corresponding sound
        if (fEnemyHealth < fLastHealth)
        {
            TakingDamageSound.Play();
            fLastHealth = fEnemyHealth;
        }
        else
        {
            fLastHealth = fEnemyHealth;
        }


        if (fEnemyHealth > 0)                                                                                            // if the enemies health is greater than zero this logic will be executed
        {
            if (LineOfSightCheck() == true && tPlayer.GetComponent <PlayerController>().bBossFightCameraActive == false) // if the line of sight returns true or the enemy is damaged
            {
                if (AttackSound.isPlaying == false)                                                                      // check to see if the attack sound is playing because we dont want overlaping sounds
                {
                    AttackSound.Play();
                }
                Attack();                 // the enemy attacks the player
            }
            else
            {
                Patrol();                 // if the enemy is spotted than the enemy goes back to patrolling
                AttackSound.Stop();       // stop playing the attack sound if it is playing
            }
        }
        else                                                                          // if the health is less than zero than the enemy is dead
        {
            Vector3 v3DeathPosition = transform.position;                             // set the death position
            DropFuel(v3DeathPosition);                                                // drop the fuel on this position
            Instantiate(DeathXplosionEffect, transform.position, transform.rotation); // create a particle system that plays on awake
            Destroy(gameObject);                                                      // destroy this enemy
        }

        float fDistanceBetweenThisAndPlayer = Vector3.Distance(transform.position, tPlayer.transform.position);

        if (fDistanceBetweenThisAndPlayer < 12f)
        {
            if (BuzzingSound.isPlaying == false)
            {
                BuzzingSound.Play();
            }
            BuzzingSound.volume = Mathf.Clamp((1 * fDistanceBetweenThisAndPlayer), 0.01f, 0.065f);
        }
        else
        {
            BuzzingSound.Stop();
        }
    }
예제 #2
0
    void Update()
    {
        if (fEnemyHealth < fLastHealth)
        {
            TakingDamageSound.Play();
            fLastHealth = fEnemyHealth;
        }
        else
        {
            fLastHealth = fEnemyHealth;
        }

        if (fEnemyHealth > 0)
        {
            RaycastHit2D blockedInfoRight = Physics2D.Raycast(transform.position, Vector2.right, 5.1f, blockLayerMask);
            RaycastHit2D blockedInfoLeft  = Physics2D.Raycast(transform.position, Vector2.left, 5.1f, blockLayerMask);
            if (LineOfSightCheck() == true && tPlayer.GetComponent <PlayerController>().bBossFightCameraActive == false || fEnemyHealth < fEnemyMaxHealth)
            {
                animator.SetBool("AttackPlayer", true);
                //Debug.Log("Player Sighted");
                if (AttackSound.isPlaying == false)
                {
                    AttackSound.Play();
                }
                Attack();
            }
            else
            {
                animator.SetBool("AttackPlayer", false);
                AttackSound.Stop();
                Patrol();
                //Debug.Log("Patrol");
            }
        }
        else
        {
            Vector3 v3DeathPosition = transform.position;
            DropFuel(v3DeathPosition);
            Instantiate(DeathXplosionEffect, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }