Example #1
0
 private void Update()
 {
     if (player.GetComponent <Health>().GetIsDead() && !GetComponent <Health>().GetIsDead())
     {
         GetComponent <NavMeshAgent>().isStopped = true;
     }
     if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
     {
         if (!GetComponent <Health>().GetIsDead() && Aggro() && combatant.CanAttack(player))
         {
             playerLastSeen = 0f;
             combatant.Attack(player);
             GetComponent <NavMeshAgent>().speed = chaseSpeed;
         }
         else if (playerLastSeen < suspicionTimer)
         {
             GetComponent <ActionAgenda>().CancelCurrentAction();
         }
         else
         {
             if (isGuard && !GetComponent <Health>().GetIsDead())
             {
                 Patrol();
             }
             else
             {
                 combatant.Cancel();
             }
         }
     }
     playerLastSeen   += Time.deltaTime;
     timeSinceArrival += Time.deltaTime;
 }
Example #2
0
        void FixedUpdate()
        {
            if (m_Unit.m_NavMeshAgent.isStopped)
            {
                return;
            }

            switch (m_State)
            {
            case PlayerState.Idle:
                CheckNewAction();
                break;

            case PlayerState.Moving:
                m_Unit.Move(m_LastHit.point);
                CheckNewAction();
                if (m_Unit.HasArrived())
                {
                    m_State = PlayerState.Idle;
                }
                break;

            case PlayerState.MovingWithinRange:
                m_Unit.Move(m_LastHit.point);
                CheckNewAction();
                if (m_Combatant.IsInRange())
                {
                    m_State = PlayerState.Attacking;
                }
                break;

            case PlayerState.Attacking:
                m_Unit.Stop();
                StartCoroutine(m_Combatant.Attack());
                break;
            }
        }
Example #3
0
    void HandleAttack(InputAction.CallbackContext context)
    {
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());

        combatant.Attack(mousePosition - new Vector2(transform.position.x, transform.position.y));
    }