Пример #1
0
 void Update()
 {
     /*if (audioSource.isPlaying == false)
      * {
      *  audioSource.clip = idleAudio;
      *  audioSource.Play();
      * }*/
     if (isDead == false)
     {
         GameManager.instance.BossHealthUpdater(health);
         transform.LookAt(new Vector3(playerTransform.position.x, transform.position.y, playerTransform.position.z));
         if (State == EnemyState.Special) // --FLEEING--------------------------------------------------------
         {
             if (SpecialActive == false)
             {
                 StartCoroutine(SpecialAbility());
             }
         }
         else if (State == EnemyState.Attacking) // --ATTACKING--------------------------------------------------
         {
             if (attackTimerStarted == false)    // Start attacktimer, when it ends switch back to roaming
             {
                 StartCoroutine("Attack");
             }
             audioSource.PlayOneShot(attackAudio, 1);
         }
         if (timerStarted == false)
         {
             timer        = Random.Range(timeToBottleMin, timeToBottleMax);
             timerStarted = true;
         }
         else
         {
             timer -= 0.1f;
         }
         if (timer <= 0)
         {
             State = EnemyState.Special;
         }
         if (health <= 0)
         {
             isDead = true;
         }
     }
     else
     {
         //disable stuff here
         if (perkSystem.LifeSteal == true)
         {
             perkSystem.LifeStealHeal();
         }
         Destroy(gameObject);
     }
 }
Пример #2
0
    void Update()
    {
        if (health <= 0)
        {
            GameObject Death = (GameObject)Instantiate(DeathParticle, new Vector3(this.transform.position.x, this.transform.position.y + 1.14f, this.transform.position.z), transform.rotation);
            Destroy(Death, 1);
            float healthDropChance = Random.Range(0, 5);
            if (healthDropChance == 4)
            {
                GameObject.Instantiate(healOrb, this.transform.position, transform.rotation);
            }
            //player.GetComponent<PlayerController>().ExpGain(expWorth);
            isDead = true;
        }

        /*if (audioSource.isPlaying == false)
         * {
         *  audioSource.clip = idleAudio;
         *  audioSource.Play();
         * }*/
        if (isDead == false)
        {
            transform.LookAt(new Vector3(playerTransform.position.x, transform.position.y, playerTransform.position.z));
            if (State == EnemyState.Positioning) // --ROAMING--------------------------------------------------
            {
                agent.speed = Speed;
                float distance = Vector3.Distance(playerTransform.transform.position, transform.position);

                if (distance >= maxPositioningDistance)
                {
                    MoveAtPlayer(1);
                    strafing = false;
                }
                else if (distance <= minPositioningDistance)
                {
                    MoveAtPlayer(-1);
                    strafing = false;
                }
                else if (distance >= minPositioningDistance && distance <= maxPositioningDistance)
                {
                    if (strafing == false)
                    {
                        rand = Random.Range(0, 2);
                    }
                    if (rand <= 0.5)
                    {
                        StrafeRight();
                    }
                    if (rand > 0.5)
                    {
                        StrafeLeft();
                    }
                }
                RaycastHit hit;
                if (Physics.Raycast(ProjectileLauncher.transform.position, ProjectileLauncher.transform.TransformDirection(Vector3.forward), out hit, maxPositioningDistance))
                {
                    if (hit.collider.tag == "Player" && attackOnCooldown == false)
                    {
                        State = stateChanges.stateAfterDetectTarget;
                    }
                }
            }
            else if (State == EnemyState.Chasing) // --CHASING--------------------------------------------------
            {
                //animator.SetInteger("AnimPos", 2); // Can be used to set aggressive animation or something.

                agent.speed = Speed * chaseSpeedMultiplier;

                //playerDetected = Physics.OverlapSphere(transform.position, roamingDetectionRadius, (1 << LayerMask.NameToLayer("Player"))); // Locates players using layers.

                //transform.rotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
                float distance = Vector3.Distance(playerTransform.transform.position, transform.position);
                if (chaseOnCoolDown == false)
                {
                    if (distance >= attackDistance) // if outside of attack distance, move at player
                    {
                        MoveAtPlayer(1);
                    }
                    else if (distance < attackDistance) // If inside attack distance, change state (most likely to attack state)
                    {
                        State = stateChanges.stateAfterCloseToTarget;
                    }
                }
            }
            else if (State == EnemyState.Special) // --FLEEING--------------------------------------------------------
            {
                if (isFleeing == false)
                {
                    if (audioSource.isPlaying == false)
                    {
                        audioSource.PlayOneShot(damagedAudio, 1);
                    }
                    agent.speed = Speed * fleeingSpeedMultiplier;
                    StartCoroutine("FleeingTimer");
                }
                else if (isFleeing)
                {
                    MoveAtPlayer(-1);
                }
            }
            else if (State == EnemyState.Attacking) // --ATTACKING--------------------------------------------------
            {
                if (attackTimerStarted == false)    // Start attacktimer, when it ends switch back to roaming
                {
                    StartCoroutine("Attack");
                }
                audioSource.PlayOneShot(attackAudio, 1);
            }
        }
        else
        {
            //disable stuff here
            MoveAtPlayer(0);
            if (perkSystem.LifeSteal == true)
            {
                perkSystem.LifeStealHeal();
            }
            Destroy(gameObject);
        }
    }
Пример #3
0
    void FixedUpdate()
    {
        /*if (audioSource.isPlaying == false)
         * {
         *  audioSource.clip = idleAudio;
         *  audioSource.Play();
         * }*/
        if (isDead == false)
        {
            GameManager.instance.BossHealthUpdater(health);
            if (State == EnemyState.Chasing) // --CHASING--------------------------------------------------
            {
                agent.acceleration = baseAcceleration;
                //animator.SetInteger("AnimPos", 2); // Can be used to set aggressive animation or something.

                agent.speed = Speed * chaseSpeedMultiplier;

                //playerDetected = Physics.OverlapSphere(transform.position, roamingDetectionRadius, (1 << LayerMask.NameToLayer("Player"))); // Locates players using layers.

                //transform.rotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
                float distance = Vector3.Distance(playerTransform.transform.position, transform.position);
                if (chaseOnCoolDown == false)
                {
                    if (distance >= attackDistance) // if outside of attack distance, move at player
                    {
                        MoveAtPlayer(1);
                    }
                    else if (distance < attackDistance) // If inside attack distance, change state (most likely to attack state)
                    {
                        State = stateChanges.stateAfterCloseToTarget;
                    }
                }
                RaycastHit hit;
                if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, maxChaseRange))
                {
                    if (hit.collider.tag == "Player" && attackTimerStarted == false && chargeOnCooldown == false)
                    {
                        State = stateChanges.stateAfterDetectTarget;
                    }
                }
            }
            else if (State == EnemyState.Special) // --SPECIAL--------------------------------------------------------
            {
                if (isCharging == false)
                {
                    /*if (audioSource.isPlaying == false)
                     *  audioSource.PlayOneShot(damagedAudio, 1);*/
                    StartCoroutine("SpecialTimer");
                }
                else
                {
                    float dist = agent.remainingDistance;
                    if (dist != Mathf.Infinity && agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance == 0)
                    {
                        State = stateChanges.stateAfterSpecial;
                        StartCoroutine(ChargeCooldownTimer());
                        isCharging = false;
                    }
                }
            }
            else if (State == EnemyState.Attacking) // --ATTACKING--------------------------------------------------
            {
                if (attackTimerStarted == false)    // Start attacktimer, when it ends switch back to roaming
                {
                    StartCoroutine("Attack");
                }
                audioSource.PlayOneShot(attackAudio, 1);
            }
            if (health <= 0)
            {
                isDead = true;
            }
        }
        else
        {
            //disable stuff here
            MoveAtPlayer(0);
            if (perkSystem.LifeSteal == true)
            {
                perkSystem.LifeStealHeal();
            }
            Destroy(gameObject);
        }
    }