public void Move() { if (NewPathScript.PathPoints.Count > 0 && PlayerState == States.ReadyToMove) { _endPosition = NewPathScript.GetPathPoint(); PlayerState = States.Moving; _lengthBtwPoints = (int)Mathf.Abs(_startPosition.x - _endPosition.x); if (_lengthBtwPoints == 0) { _lengthBtwPoints = (int)Mathf.Abs(_startPosition.z - _endPosition.z); } } if (PlayerState == States.Moving) { _time += Time.deltaTime; transform.position = LerpMoveTo(_startPosition, _endPosition, TimeToReachNextTile * _lengthBtwPoints); RingsRotation(RotationSpeed); if (_time >= TimeToReachNextTile * _lengthBtwPoints) { _time = 0; PlayerState = States.ReadyToMove; transform.position = _endPosition; _startPosition = _endPosition; } } }
IEnumerator NewPositionDelay() { Vector3 endPosition; float x = 0; float z = 0; yield return(new WaitForSeconds(0.2f)); newPosition = Player.transform.position; Debug.LogError("newPosition = " + newPosition); if (oldPosition == newPosition) { StartCoroutine(LaterUnblockAbortMove()); yield break; } else if (oldPosition.x == newPosition.x) { if ((oldPosition.z - newPosition.z) > 0) { z = Mathf.Floor(newPosition.z); } else { z = Mathf.Ceil(newPosition.z); } x = oldPosition.x; } else if (oldPosition.z == newPosition.z) { if ((oldPosition.x - newPosition.x) > 0) { x = Mathf.Floor(newPosition.x); } else { x = Mathf.Ceil(newPosition.x); } z = oldPosition.z; } endPosition = new Vector3(x, 0, z); Player.GetComponent <NewPlayerController>()._startPosition = newPosition; Player.GetComponent <NewPlayerController>()._endPosition = endPosition; PlayerGhost.GetComponent <PlayerGhostScript>()._startPosition = endPosition; PlayerGhost.GetComponent <PlayerGhostScript>()._endPosition = endPosition; NewPathScript.PreviousPoint = endPosition; NewPathGhostScript.GhostPreviousPoint = endPosition; PlayerGhost.transform.position = endPosition; NewPathScript.ClearPathPoints(); NewPathGhostScript.ClearPathPoints(); GameObject[] PathPoints = GameObject.FindGameObjectsWithTag("Path"); foreach (var e in PathPoints) { Destroy(e); } StartCoroutine(LaterUnblockAbortMove()); }