Example #1
0
 private void Walk()
 {
     _navAgent.SetDestination(_target.position);
     if (Mathf.Approximately(_navAgent.velocity.magnitude, 0f))
     {
         CharacterAnimController.Walk(_animator, false);
     }
     else
     {
         CharacterAnimController.Walk(_animator, true);
         float forwardSpeed = _navAgent.velocity.magnitude;
         CharacterAnimController.SpeedWalk(_animator, forwardSpeed);
     }
 }
Example #2
0
    private void Update()
    {
        if (!IsInTeam && _commanderTransform)
        {
            if (Vector3.Distance(_commanderTransform.position, transform.position) < findRadius)
            {
                IsInTeam = true;
            }
        }
        else
        {
            if (isCommander)
            {
                if (Input.GetMouseButton(0))
                {
                    _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(_ray, out _hit, 100f))
                    {
                        _navAgent.SetDestination(_hit.point);
                    }
                }
            }
            else
            {
                if (_commanderTransform)
                {
                    _navAgent.SetDestination(_commanderTransform.position);
                }
            }
            if (Mathf.Approximately(_navAgent.velocity.magnitude, 0f))
            {
                CharacterAnimController.Walk(_animator, false);
            }
            else
            {
                CharacterAnimController.Walk(_animator, true);
                float forwardSpeed = _navAgent.velocity.magnitude;
                CharacterAnimController.SpeedWalk(_animator, forwardSpeed);
            }
        }

        foreach (EnemyUnit enemyUnit in GameManager.Instance.EnemyUnits)
        {
            if (Vector3.Distance(enemyUnit.transform.position, transform.position) < attackRange)
            {
                transform.LookAt(enemyUnit.transform.position);
                weaponPlace.Attack();
            }
        }
    }
Example #3
0
 private void Update()
 {
     if (Input.GetMouseButton(0))
     {
         _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(_ray, out _hit, 100f))
         {
             navAgent.speed = 5;
             navAgent.SetDestination(_hit.point);
             navAgent.speed = moveSpeed;
         }
     }
     if (Mathf.Approximately(navAgent.velocity.magnitude, 0f))
     {
         CharacterAnimController.Walk(animator, false);
     }
     else
     {
         CharacterAnimController.Walk(animator, true);
         float forwardSpeed = navAgent.velocity.magnitude;
         CharacterAnimController.SpeedWalk(animator, forwardSpeed);
     }
 }