Hi All,
I'm a bit confused. Variable assignment within a while loop isn't working and I cant figure out as to why.
[This is being called in the Awake() Function]
_currentTile = startingTile;
int safetyBreak = 0;
while (!_hasReachedEndX) {
safetyBreak++;
if (safetyBreak > 100) {
Debug.Log("SafteyBreakX");
break;
}
if (_currentTile.transform.position.x > endingTile.transform.position.x)
_currentTile = MoveLeft();
else if (_currentTile.transform.position.x < endingTile.transform.position.x)
_currentTile = MoveRight();
else
_hasReachedEndX = true;
}
This is the while loop itself. I'm trying to assign the current value, which is taken from the MoveLeft function.
Within the method, there is an assignment from point A (the currentIndex) to point B (the nextIndex)
private GameObject MoveLeft() {
tilePath.Add(_currentTile);
_currentTileIndex = allGeneratedTiles.IndexOf(_currentTile);
int _nextTileIndex = _currentTileIndex--;
return allGeneratedTiles[_nextTileIndex];
I've tried many different iterations and log outputs from this I've seen:
- The nextTileIndex is being assigned correctly
- currentTileIndex is also assigned correctly
for some reason the 'return' isn't returning the correct GameObject from the list (it's returning the same currentTile over and over which tells me that the currentTile is never re-assigned to point to the 'nextTileIndex'.
Any thoughts? I'm lost.
One thing I would like to note, if I add `allGeneratedTiles[_nextTileIndex + 1]` or negative 1 the return is actually returning
I've also tried to make the `_nextTileIndex` a class level variable but that also did not work and to assign the `_currentTile`within the MoveLeft function itself.
Thanks
↧