示例#1
0
文件: Unit.cs 项目: Artheg/Last_Stand
    public void SetDestination(Vector3 destination, bool forced = false)
    {
        if (Speed <= 0f)
        {
            return;
        }
        if (navMeshAgent == null)
        {
            InitNavMeshAgent();
        }
        if (navMeshAgent.destination == destination)
        {
            return;
        }
        if (forced && OnForceDestinationSet != null)
        {
            OnForceDestinationSet();
        }
        isCurrentDestinationForced = forced;

        navMeshAgent.isStopped = true;
        navMeshAgent.ResetPath();
        navMeshAgent.isStopped = false;

        CurrentTargetPosition = destination;

        if (CurrentTarget != null && CurrentTarget.IsFrendly(this))
        {
            navMeshAgent.stoppingDistance = 0;
        }
        else
        {
            navMeshAgent.stoppingDistance = AttackRange + stoppingThreshold;
        }

        navMeshAgent.SetDestination(destination);
        IsMoving = true;
    }