示例#1
0
    void MoveTest3()
    {
        if (AllowMove & !_doReset & !UIOpen)
        {
            if (ActiveUI != null)
            {
                ActiveUI.CloseUI();
            }
            Debug.Log("Start Move");
            float moveStep = Time.deltaTime * MoveSpeed;
            if (_checkDoneUp <= _checkDoneDown)
            {
                if (PlayerTransform.transform.position == Checkpoints[_checkpointIndex].position &&
                    _moveDone < _checkDoneUp)
                {
                    _checkpointIndex++;
                }
                if (_checkpointIndex > 7)
                {
                    _checkpointIndex = 0;
                }
                if (PlayerTransform.transform.position != Checkpoints[_checkpointIndex].position)
                {
                    PlayerTransform.transform.position = Vector3.MoveTowards(PlayerTransform.transform.position,
                                                                             Checkpoints[_checkpointIndex].position, moveStep);
                    _clockUiScript.RedOverlay.fillAmount += MoveCost * Time.deltaTime;
                }
                if (PlayerTransform.transform.position == Checkpoints[_checkpointIndex].position &&
                    _moveDone < _checkDoneUp)
                {
                    _moveDone++;
                    //_clockUiScript.RedOverlay.fillAmount += MoveCost;
                }
            }

            if (_checkDoneDown < _checkDoneUp)
            {
                if (PlayerTransform.transform.position == Checkpoints[_checkpointIndex].position &&
                    _moveDone < _checkDoneDown)
                {
                    _checkpointIndex--;
                }
                if (_checkpointIndex < 0)
                {
                    _checkpointIndex = 7;
                }
                if (PlayerTransform.transform.position != Checkpoints[_checkpointIndex].position)
                {
                    PlayerTransform.transform.position = Vector3.MoveTowards(PlayerTransform.transform.position,
                                                                             Checkpoints[_checkpointIndex].position, moveStep);
                    _clockUiScript.RedOverlay.fillAmount += MoveCost * Time.deltaTime;
                }
                if (PlayerTransform.transform.position == Checkpoints[_checkpointIndex].position &&
                    _moveDone < _checkDoneDown)
                {
                    _moveDone++;
                    // _clockUiScript.RedOverlay.fillAmount += MoveCost;
                }
            }

            if (_moveDone == _checkDoneDown || _moveDone == _checkDoneUp)
            {
                ResetValues();
                AllowMove = false;
                if (ClockUI.activeInHierarchy)
                {
                    ActiveUI = Checkpoints[_checkpointIndex].GetComponent <SpaceManagerScript>();
                    ActiveUI.OpenUI();
                    UIOpen = true;
                }
            }
        }
        if (_clockUiScript.RedOverlay.fillAmount >= 1)
        {
            _doReset = true;
        }
    }
    void MovePlayer()// move the player to the spaces clicked on. The direction found in DirectionChecker function
    {
        if (AllowMove && !TurnOver && !UIOpen && !_spacePause)
        {
            if (ActiveSpace != null) //To remove error on first turn.
            {
                ActiveSpace.CloseUI();
            }
            //Debug.Log("Start Move");
            float moveStep = Time.deltaTime * MoveSpeed;
            if (_checksUp <= _checksDown)
            {
                if (Player.transform.position == Spaces[_currentSpaceIndex].position &&
                    _movesDone < _checksUp)
                {
                    _currentSpaceIndex++;
                    _movesLeft = _checksUp - _movesDone;
                    Debug.Log("Moves Left: " + _movesLeft);
                }
                if (_currentSpaceIndex > _spaces)
                {
                    _currentSpaceIndex = 0;
                }
                if (Player.transform.position != Spaces[_currentSpaceIndex].position)
                {
                    Player.transform.position = Vector3.MoveTowards(Player.transform.position,
                                                                    Spaces[_currentSpaceIndex].position, moveStep);
                    //_clockUiScript.FillAmount += MoveCost * Time.deltaTime;
                }
                if (Player.transform.position == Spaces[_currentSpaceIndex].position &&
                    _movesDone < _checksUp)
                {
                    _spacePause = true;
                    Invoke("MovePaused", MovePauseTimer);
                    _movesDone++;
                }
                if (Player.transform.position != Spaces[TargetIndex].position)
                {
                    _clockUiScript.FillAmount += (MoveCost * _checksUp) * Time.deltaTime;
                }
            }

            if (_checksDown < _checksUp)
            {
                if (Player.transform.position == Spaces[_currentSpaceIndex].position &&
                    _movesDone < _checksDown)
                {
                    _currentSpaceIndex--;
                    _movesLeft = _checksDown - _movesDone;
                    Debug.Log("Moves Left: " + _movesLeft);
                }
                if (_currentSpaceIndex < 0)
                {
                    _currentSpaceIndex = _spaces;
                }
                if (Player.transform.position != Spaces[_currentSpaceIndex].position)
                {
                    Player.transform.position = Vector3.MoveTowards(Player.transform.position,
                                                                    Spaces[_currentSpaceIndex].position, moveStep);
                    //_clockUiScript.FillAmount += MoveCost * Time.deltaTime; //Move cost every tile
                }
                if (Player.transform.position == Spaces[_currentSpaceIndex].position &&
                    _movesDone < _checksDown)
                {
                    _spacePause = true;
                    Invoke("MovePaused", MovePauseTimer);
                    _movesDone++;
                }
                if (Player.transform.position != Spaces[TargetIndex].position)
                {
                    _clockUiScript.FillAmount += (MoveCost * _checksDown) * Time.deltaTime;
                }
            }

            if (_movesDone == _checksDown || _movesDone == _checksUp)
            {
                ResetValues();
                AllowMove = false;
                if (ClockUI.activeInHierarchy)                                                    //A safty check so the space ui dont open when time is out.
                {
                    ActiveSpace = Spaces[_currentSpaceIndex].GetComponent <SpaceManagerScript>(); //Makes a easy to use ref for the current spaces UI.
                    ActiveSpace.OpenUI();
                    UIOpen = true;
                }
            }
        }
        if (_clockUiScript.FillAmount >= 1)
        {
            TurnOver = true;
        }
    }