Exemplo n.º 1
0
    public void SetTargetPoint(NavMeshTargetPoint MoveTargetPoint)
    {
        if (_Agent.pathStatus == NavMeshPathStatus.PathInvalid)
        {
            return;
        }

        if (_LastMoveTargetPoint == null || (_LastMoveTargetPoint != MoveTargetPoint && _MoveTargetPoint == null))
        {
            _MoveTargetPoint    = MoveTargetPoint;
            _MoveTargetPosition = MoveTargetPoint.transform.position;
            _Agent.SetDestination(MoveTargetPoint.transform.position);
            _DestinationElapsedTime = 0.0f;
        }
    }
Exemplo n.º 2
0
    private IEnumerator Routine_Move()
    {
        if (_Agent.pathStatus == NavMeshPathStatus.PathInvalid)
        {
            yield return(new WaitForSeconds(1.0f));

            yield break;
        }
        //次の地点が見つかるまで待機
        while (_Agent.pathStatus != NavMeshPathStatus.PathInvalid && _MoveTargetPoint == null && !CalcNextPoint())
        {
            yield return(new WaitForSeconds(0.5f));

            Debug.Log("Serching");
        }

        if (Random.Range(0.0f, 100.0f) <= _RunPossibility)
        {
            //走り
            _CharaState = eCharaState.isRunning;
            _Animator.SetTrigger(_ID_Run);
            _Agent.speed = _RunSpeed;
        }
        else
        {
            //歩き
            _CharaState = eCharaState.isWalking;
            _Animator.SetTrigger(_ID_Walk);
            _Agent.speed = _WalkSpeed;
        }

        _Agent.isStopped = false;

        while (true)
        {
            _Agent.Move(transform.forward * _Agent.speed * 0.75f * Time.deltaTime);

            //到着まで移動
            if (_MoveTargetPoint != null && _MoveTargetPoint.gameObject.activeInHierarchy)
            {
                if (Vector3.SqrMagnitude(Vector3.Scale(_MoveTargetPosition, new Vector3(1, 0, 1)) - Vector3.Scale(transform.position, new Vector3(1, 0, 1))) < 0.01f)
                {
                    _LastMoveTargetPoint = _MoveTargetPoint;
                    _MoveTargetPoint     = null;
                    break;
                }
            }
            else
            {
                if (Vector3.SqrMagnitude(Vector3.Scale(_MoveTargetPosition, new Vector3(1, 0, 1)) - Vector3.Scale(transform.position, new Vector3(1, 0, 1))) < 0.1f)
                {
                    _LastMoveTargetPoint = _MoveTargetPoint;
                    _MoveTargetPoint     = null;
                    break;
                }
            }

            _DestinationElapsedTime += Time.deltaTime;
            if (_DestinationElapsedTime >= _GiveUpAribalSeconds)
            {
                break;
            }

            yield return(null);
        }

        if (Random.Range(0.0f, 100.0f) <= _IntervalPossibility)
        {
            _MoveState = eMoveState.inIntarval;
        }
        else
        {
            _MoveState = eMoveState.isMoving;
        }
    }