Example #1
0
    private void Update()
    {
        _patrolPoints = _patrol.GetPatrolPoints();

        if (_patrolPoints.Count > 0)
        {
            if (_currentDestination == null)
            {
                _currentDestinationIndex = 0;
                _currentDestination      = _patrolPoints[0].transform.position;
            }

            if (Vector3.Distance(transform.position, _currentDestination) < 0.2f)
            {
                Debug.Log("cel osiagniety: " + _currentDestinationIndex);
                _currentDestinationIndex++;
                if ((_currentDestinationIndex) >= _patrolPoints.Count)
                {
                    _currentDestinationIndex = 0;
                    _currentDestination      = _patrolPoints[_currentDestinationIndex].transform.position;
                }
                else
                {
                    _currentDestination = _patrolPoints[_currentDestinationIndex].transform.position;
                }
            }

            _player.SetDestination(_currentDestination);
        }
    }