Hey all,
I am making a Monopoly clone and I am having a problem with going around the board. I am using tiles and storing their positions in a List which moves the player depending on the dice roll.
My problem is when I go around the board and get to the last tile I am not sure how to loop it back to the beginning of the list so the player will continue pass go and start moving around the board again.
My current code is:
IEnumerator movePlayer(Token currentPlayerNumber, int rollValue)
{
isPlayerMoving = true;
//Get tile player is currently on
int currentTile = currentPlayerNumber.CurrentTileID;
//Move player according to dice value
for(int i = 0; i < rollValue; i++)
{
float t = 0;
//Makes the player move one tile every roll until it has reached the end position
Vector3 startPosition = tile[(currentTile + i)].transform.position + playerPosition[currentPlayerNumber.ID];
Vector3 endPosition = tile[(currentTile + i + 1)].transform.position + playerPosition[currentPlayerNumber.ID];
while (t < 1f)
{
t += Time.deltaTime * 4f;
currentPlayerNumber.transform.position = Vector3.Lerp(startPosition, endPosition, t);
yield return null;
}
yield return null;
}
//Reset current tile position
currentPlayerNumber.CurrentTileID = currentTile + rollValue;
isPlayerMoving = false;
StartCoroutine(tileActions());
}
Any one have any ideas on how to achieve this?