Increasing platform size

This commit is contained in:
Norbi Peti 2020-11-08 00:04:49 +01:00
parent ee3be5496c
commit 3e57a06752
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -11,20 +11,24 @@ public class PlatformSpawner : MonoBehaviour
public Transform player; public Transform player;
public int maxSize = 5; public int maxSize = 5;
public int maxLevel = 5; public int maxLevel = 5;
public int platformCount = 2;
private Vector3 _spawnDiff; private Vector3 _spawnDiff;
private int _level = 0; private int _level;
private Random _random = new Random(); private Random _random = new Random();
private Vector3 _lastPlatformPos; private Vector3 _lastPlatformPos;
private OwnCharacterController _playerController; private OwnCharacterController _playerController;
private float _lastLevel0Pos; private float _lastLevel0Pos;
private int _totalLevel;
private int _remainingPlatforms;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
_spawnDiff = platformLeft.position - player.position; _spawnDiff = platformLeft.position - player.position;
_lastPlatformPos = platformRight.position; _lastPlatformPos = platformRight.position;
_playerController = player.GetComponent<OwnCharacterController>(); _playerController = player.GetComponent<OwnCharacterController>();
_remainingPlatforms = platformCount;
} }
// Update is called once per frame // Update is called once per frame
@ -43,19 +47,26 @@ public class PlatformSpawner : MonoBehaviour
_lastPlatformPos = pos; _lastPlatformPos = pos;
if (_level == 0) if (_level == 0)
_lastLevel0Pos = pos.x; _lastLevel0Pos = pos.x;
int rand = _random.Next(10); if (--_remainingPlatforms != 0) return;
if (rand == 1 && _level < maxLevel) int rand = _random.Next(2);
switch (rand)
{ {
_level++; case 0 when _level < maxLevel:
_lastPlatformPos.y++; case 1 when _level == 0:
_playerController.SetCheckpoint(_lastPlatformPos); _level++;
} _lastPlatformPos.y++;
else if (rand == 2 && _level > 1) _playerController.SetCheckpoint(_lastPlatformPos);
{ break;
_level--; case 0 when _level > 1:
_lastPlatformPos.y++; case 1 when _level == maxLevel:
_playerController.SetCheckpoint(_lastPlatformPos); _level--;
_lastPlatformPos.y -= 2; _lastPlatformPos.y++;
_playerController.SetCheckpoint(_lastPlatformPos);
_lastPlatformPos.y -= 2;
break;
} }
_totalLevel++;
_remainingPlatforms = (1 + _totalLevel) * platformCount;
} }
} }