Exemplo n.º 1
0
        /// <summary>
        ///     Основной вызываемый из контроллера врага метод - отвечает за режим боя
        /// </summary>
        /// <param name="archrival"></param>
        /// <param name="deltaTime"></param>
        public void Fight(GameObject archrival, float deltaTime)
        {
            timer         += deltaTime;
            reactionTimer += deltaTime;
            SpecialAbilityActivator();
            if (timer > effectsDisplayTime)
            {
                DisableEffects();
            }
            if (specialAbility)
            {
                SpecialAbility(archrival.transform.position);
            }
            else
            {
                //Рассчет расстояния до потивника
                var distance = Mathf.Sqrt(Mathf.Pow(archrival.transform.position.x - enemyTransform.position.x, 2) +
                                          Mathf.Pow(archrival.transform.position.y - enemyTransform.position.y, 2) +
                                          Mathf.Pow(archrival.transform.position.z - enemyTransform.position.z, 2));
                if (distance > currentAttackDistance)
                {
                    //Debug.Log("MoveToPlayer");
                    move.Continue();
                    move.Move(archrival.transform.position, Speed.Walk);
                    move.Rotate(RotateDirection(archrival.transform.position));
                    if (timer > 15f)
                    {
                        AttackToChaseEvent(enemyTransform.name);
                    }
                    if (switchMode)
                    {
                        gun.enabled   = true;
                        knife.enabled = false;
                        //Debug.Log("MoveToPlayer");
                        move.Continue();
                        move.Move(archrival.transform.position, Speed.Run);
                        move.Rotate(RotateDirection(archrival.transform.position));
                    }
                    else
                    {
                        gun.enabled   = false;
                        knife.enabled = true;
                        //Debug.Log("ThrowToPlayer");
                        move.Continue();
                        move.Move(archrival.transform.position, Speed.Throw);
                        move.Rotate(RotateDirection(archrival.transform.position));
                        if (distance >= switchDistance)
                        {
                            timer                 = 0f;
                            switchMode            = !switchMode;
                            currentAttackDistance = priorityDistance;
                        }
                    }
                }
                else if (distance <= currentAttackDistance)
                {
                    move.Stop();
                    if (switchMode)
                    {
                        gun.enabled   = true;
                        knife.enabled = false;
                        move.Rotate(RotateDirection(archrival.transform.position));
                        if (timer >= shootSpeed)
                        {
                            if (choseAim)
                            {
                                if (reactionTimer > reaction)
                                {
                                    RangeAttack(reactionAim);
                                    choseAim = false;
                                }
                            }
                            else
                            {
                                //Выбор цели и запуск таймера реакции
                                reactionTimer = 0f;
                                reactionAim   = ShootDirection(archrival.transform.position, rangeAccuracy);
                                choseAim      = true;
                            }
                        }

                        if (distance <= switchDistance)
                        {
                            timer                 = 0f;
                            switchMode            = !switchMode;
                            currentAttackDistance = alternativeDistance;
                        }
                    }
                    else
                    {
                        gun.enabled   = false;
                        knife.enabled = true;
                        move.Rotate(RotateDirection(archrival.transform.position));
                        if (timer >= hitSpeed)
                        {
                            MeleeAttack();
                            meleeHitCount++;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void Stop()
 {
     move.Stop();
 }