예제 #1
0
    public void MoveToRandomPoint()
    {
        SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();

        _logicState = LogicState.Walking;
        snpc.PlaySpriteAnimator();

        _pointWalkCount = (int)Random.Range(6, 10);

        if (!_lastTarget)
        {
            int random_range = _currentTarget.GetEdges().Length;
            _lastTarget    = _currentTarget;
            _currentTarget = _currentTarget.GetEdges()[(int)Random.Range(0, random_range)].GetComponent <Node>();
        }
        else
        {
            if (Random.Range(0f, 1f) < 0.05f)
            {
                Node aux_target = _currentTarget;
                _currentTarget = _lastTarget;
                _lastTarget    = aux_target;
            }
            else
            {
                GameObject[] targets_array = _currentTarget.GetEdges().Clone() as GameObject[];
                int          random_range  = targets_array.Length;
                _lastTarget    = _currentTarget;
                _currentTarget = targets_array[(int)Random.Range(0, random_range)].GetComponent <Node>();
            }
        }
    }
예제 #2
0
    private void MoveToNextRandomPoint()
    {
        _pointWalkCount--;

        if (_pointWalkCount > 0)
        {
            if (!_lastTarget)
            {
                int random_range = _currentTarget.GetEdges().Length;
                _lastTarget    = _currentTarget;
                _currentTarget = _currentTarget.GetEdges()[(int)Random.Range(0, random_range)].GetComponent <Node>();
            }
            else
            {
                if (Random.Range(0f, 1f) < _backProbability)
                {
                    Node aux_target = _currentTarget;
                    _currentTarget = _lastTarget;
                    _lastTarget    = aux_target;
                }
                else
                {
                    GameObject[] targets_array = null;

                    if (_currentTarget.GetEdges().Length != 1)
                    {
                        targets_array = new GameObject[_currentTarget.GetEdges().Length - 1];
                        int ind = 0;

                        for (int i = 0; i < _currentTarget.GetEdges().Length; i++)
                        {
                            if (_lastTarget.transform.position != _currentTarget.GetEdges()[i].transform.position)
                            {
                                targets_array[ind] = _currentTarget.GetEdges()[i];
                                ind++;
                            }
                        }
                    }
                    else
                    {
                        targets_array = _currentTarget.GetEdges().Clone() as GameObject[];
                    }

                    int random_range = targets_array.Length;
                    _lastTarget    = _currentTarget;
                    _currentTarget = targets_array[(int)Random.Range(0, random_range)].GetComponent <Node>();
                }
            }
        }
        else
        {
            _logicState = LogicState.Stand;
            SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();
            snpc.StopSpriteAnimator(true);
        }
    }
예제 #3
0
    private void MoveToDesiredNode(Node target)
    {
        Node n = _currentTarget.NextNodeTo(target);

        if (n == null || n == target) //Finish
        {
            SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();
            _logicState = LogicState.Stand;
        }
        else
        {
            _currentTarget = n;
        }
    }
예제 #4
0
 public void Awake()
 {
     snpc = GetComponent <SpriteAnimatorNpc>();
 }