Пример #1
0
 /// <summary>
 /// Stops chasing the current target.
 /// </summary>
 private void StopChasing()
 {
     targetFinder.RemoveFirstTarget();
     _isChasing         = false;
     NavMeshAgent.speed = _initialSpeed;
     _attackLogic.StopAttack();
 }
Пример #2
0
        /// <summary>
        /// Is called on mouse click.
        /// If right clicked, checks whether clicked on a damageable object or the ground.
        /// If clicked on a damageable object, attack it. If clicked on the ground, cancel attack
        /// and move to the clicked point. If clicked on a interactable object that is not a damageable object, interact with it.
        /// </summary>
        private void OnRightClick(InputAction.CallbackContext obj)
        {
            if (IsOverUI)
            {
                return;
            }

            Ray clickRay = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());

            if (Physics.Raycast(clickRay, out RaycastHit hit, 10000, clickableLayers))
            {
                GameObject objectHit = hit.collider.gameObject;

                if (objectHit.TryGetComponent(out Damageable damageable))
                {
                    _interactLogic.RemoveFocus();
                    // implementation NOT capable of area damage
                    _attackLogic.StartAttack(damageable, objectHit.GetComponent <EnemyController>());
                }

                else if (objectHit.TryGetComponent(out Interactable interactable))
                {
                    _attackLogic.StopAttack();
                    //Set as focus
                    _interactLogic.StartInteract(interactable);
                }

                // Get ground position from mouse click
                else if (Physics.Raycast(clickRay, out RaycastHit groundHit, 10000, groundLayer))
                {
                    // cancel possible ongoing attacks
                    _attackLogic.StopAttack();
                    _interactLogic.RemoveFocus();
                    Move(groundHit);
                }
            }
        }