Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (!Host.State.Equals(ActionUnit.UnitState.Move))
        {
            return;
        }
        NavMeshAgent agent = Host.GetComponent <NavMeshAgent>();

        //agent.destination = target;
        agent.isStopped = false;
        // TestCalculateSpeed();
        agent.SetDestination(Host.TargetAttack.transform.position);
        // Host.GetComponent<BaseCharacterwNav>().SetTarget(Host.TargetAttack.transform);
        // Host.FaceTarget();
        // Host.ChangeState(ActionUnit.UnitState.Move);
        // if (agent.velocity.sqrMagnitude > Mathf.Epsilon)
        // {
        //     FaceTarget(Host.TargetAttack.transform.position);
        //     // Host.transform.rotation = Quaternion.Lerp(Host.transform.rotation, Quaternion.LookRotation(agent.velocity.normalized), 0.1f);
        // }

        if (Host.IsEnemyInRangeAttack())
        {
            //stop moving
            Debug.Log("Inside Range Attack");
            agent.isStopped = true;
            // Host.GetComponent<BaseCharacterwNav>().SetTarget(null);

            Host.ChangeState(ActionUnit.UnitState.Attack);
        }
    }
Example #2
0
 public void MarkTargetAttack(ActionUnit monster)
 {
     if (Host.TargetAttack == monster)
     {
         return;
     }
     if (Host.TargetAttack != null)
     {
         Debug.Log("Change Target");
         // Host.TargetAttack.OnDestroyNotify.Detach(OnTargetDestroy);
         Host.ChangeState(ActionUnit.UnitState.Idle);
     }
     Host.TargetAttack = monster;
     if (monster != null)
     {
         // Host.TargetAttack.OnDestroyNotify.Attach(OnTargetDestroy);
         if (Host.IsEnemyInRangeAttack())
         {
             Host.ChangeState(ActionUnit.UnitState.Attack);
         }
         else
         {
             Host.ChangeState(ActionUnit.UnitState.Move);
         }
     }
 }
Example #3
0
        public void Update()
        {
            ActionUnit target = _host.TargetAttack;

            if (!target || !target.Alive || !_host.IsEnemyInRangeAttack())
            {
                // _host._navMeshAgent.enabled = false;

                _host.TargetAttack = null;
                if (Time.time - _host.TimeOfLastAttack > ((ActionUnitData)_host.CurrentStatus).baseAttackRate)
                {
                    //attack done change state
                    _host.ChangeState(ActionUnit.UnitState.Idle);
                }
                // _host._characterAnimationEventCalls.RegisterListener(CharacterAnimationEventCalls.K_ACTION_ATTACK_END)
                return;
            }
            else if (Time.time - _host.TimeOfLastAttack > ((ActionUnitData)_host.CurrentStatus).baseAttackRate)
            {
                Debug.DrawLine(_host.transform.position, _host.TargetAttack.transform.position, Color.red, 0.5f);
                _host.AnimateAttack();
                // _host._characterAnimationEventCalls.OnAttack.AddListener(_attackUnit.DamageTarget);
                _host.TimeOfLastAttack = Time.time;
            }
        }