public void ComingHome() { var distance = Mathf.Sqrt(Mathf.Pow(homePoint.x - enemyTransform.position.x, 2) + Mathf.Pow(homePoint.y - enemyTransform.position.y, 2) + Mathf.Pow(homePoint.z - enemyTransform.position.z, 2)); move.Move(homePoint); if (distance < 2f) { ComingHomeEvent(enemyTransform.name); } }
/// <summary> /// Вызываемый извне метод для патрулирования по заданному маршруту /// </summary> /// <param name="route"></param> public void Patrol(Vector3[] route) { currentPoint = route[count]; if (Distance() && count < route.Length - 1) { Debug.Log("Count: " + count); count++; } else if (Distance() && count == route.Length - 1) { PatrolEvent(enemyTransform.name); count = 0; } else if (!Distance()) { move.Move(currentPoint); } }
/// <summary> /// Метод погони /// На вход получает центр зоны патрулирования, ее радиус и объект погони /// </summary> /// <param name="aim"></param> public void Chase(GameObject aim, float deltaTime) { timer += deltaTime; ///<summary> ///определяем дистанцию от центра зоны /// </summary> var distance = Mathf.Sqrt(Mathf.Pow(aim.transform.position.x - enemyTransform.position.x, 2) + Mathf.Pow(aim.transform.position.y - enemyTransform.position.y, 2) + Mathf.Pow(aim.transform.position.z - enemyTransform.position.z, 2)); move.Move(aim.transform.position, Speed.Run); if (timer > chasingTime) { StopChase(); timer = 0f; } if (distance < priorityDistance) { AttackSwitchEvent(enemyTransform.name); } }
/// <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++; } } } } }