added bonus and side moving obstacle
This commit is contained in:
1 parent
08e050ffd3
commit
e039461a83
17 files changed
+1171
-11
No files matched your search
@@ -23,12 +23,17 @@ namespace Code.Gameplay.Level
|
||||
[SerializeField] private GameObject[] highObstacles;
|
||||
[SerializeField] private GameObject[] movingLowObstacles;
|
||||
[SerializeField] private GameObject[] movingHighObstacles;
|
||||
[SerializeField] private GameObject[] sideObstacles;
|
||||
[Range(0, 100)] [SerializeField] private int obstacleChance = 40;
|
||||
[SerializeField] private float laneDistance = 5f;
|
||||
|
||||
[Header("Coins Settings")]
|
||||
[SerializeField] private GameObject coinPrefab;
|
||||
[Range(0, 100)] [SerializeField] private int coinChance = 50;
|
||||
|
||||
[Header("Bonus Settings")]
|
||||
[SerializeField] private GameObject bonusX2Prefab;
|
||||
[Range(0, 100)] [SerializeField] private int bonusChance = 10;
|
||||
|
||||
private readonly List<GameObject> _activeTiles = new();
|
||||
private readonly List<GameObject> _activeEnvironment = new();
|
||||
@@ -74,7 +79,7 @@ namespace Code.Gameplay.Level
|
||||
var lane = Random.Range(-1, 2);
|
||||
var spawnPos = new Vector3(lane * laneDistance, 0, zPos);
|
||||
|
||||
var type = Random.Range(0, 4);
|
||||
var type = Random.Range(0, 5);
|
||||
|
||||
var prefab = type switch
|
||||
{
|
||||
@@ -82,6 +87,7 @@ namespace Code.Gameplay.Level
|
||||
1 => GetRandom(highObstacles),
|
||||
2 => GetRandom(movingLowObstacles),
|
||||
3 => GetRandom(movingHighObstacles),
|
||||
4 => GetRandom(sideObstacles),
|
||||
_ => null
|
||||
};
|
||||
|
||||
@@ -99,13 +105,28 @@ namespace Code.Gameplay.Level
|
||||
if (Random.Range(0, 100) > coinChance) return;
|
||||
|
||||
var coinLane = Random.Range(-1, 2);
|
||||
if (coinLane == occupiedLane) coinLane = (coinLane + 1 > 1) ? -1 : coinLane + 1;
|
||||
|
||||
for (var i = 0; i < 2; i++)
|
||||
if (coinLane == occupiedLane)
|
||||
{
|
||||
var spawnPos = new Vector3(coinLane * laneDistance, 1f, zPos + (i * 2f));
|
||||
var coin = Instantiate(coinPrefab, spawnPos, Quaternion.identity);
|
||||
coin.transform.SetParent(_activeTiles[^1].transform);
|
||||
coinLane = (coinLane + 1 > 1) ? -1 : coinLane + 1;
|
||||
if (coinLane == occupiedLane) coinLane = (coinLane + 1 > 1) ? -1 : coinLane + 1;
|
||||
}
|
||||
|
||||
var shouldSpawnBonus = Random.Range(0, 100) < bonusChance;
|
||||
|
||||
if (shouldSpawnBonus && bonusX2Prefab)
|
||||
{
|
||||
var spawnPos = new Vector3(coinLane * laneDistance, 1f, zPos + tileLength / 2f);
|
||||
var bonus = Instantiate(bonusX2Prefab, spawnPos, Quaternion.identity);
|
||||
bonus.transform.SetParent(_activeTiles[^1].transform);
|
||||
}
|
||||
else if (coinPrefab)
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
var spawnPos = new Vector3(coinLane * laneDistance, 1f, zPos + (i * 2f));
|
||||
var coin = Instantiate(coinPrefab, spawnPos, Quaternion.identity);
|
||||
coin.transform.SetParent(_activeTiles[^1].transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user