added coins
This commit is contained in:
1 parent
4a8a8ae916
commit
9e5f46b48c
37 files changed
+7536
-79
No files matched your search
@@ -20,12 +20,15 @@ namespace Code.Gameplay.Level
|
||||
|
||||
[Header("Obstacles Settings")] [SerializeField]
|
||||
private GameObject[] lowObstacles;
|
||||
|
||||
[SerializeField] private GameObject[] highObstacles;
|
||||
[SerializeField] private GameObject[] movingLowObstacles;
|
||||
[SerializeField] private GameObject[] movingHighObstacles;
|
||||
[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;
|
||||
|
||||
private readonly List<GameObject> _activeTiles = new();
|
||||
private readonly List<GameObject> _activeEnvironment = new();
|
||||
@@ -57,15 +60,16 @@ namespace Code.Gameplay.Level
|
||||
|
||||
if (spawnItems)
|
||||
{
|
||||
SpawnObstacle(_spawnZ);
|
||||
var occupiedLane = SpawnObstacle(_spawnZ);
|
||||
SpawnCoins(_spawnZ, occupiedLane);
|
||||
}
|
||||
|
||||
|
||||
_spawnZ += tileLength;
|
||||
}
|
||||
|
||||
private void SpawnObstacle(float zPos)
|
||||
private int SpawnObstacle(float zPos)
|
||||
{
|
||||
if (Random.Range(0, 100) > obstacleChance) return;
|
||||
if (Random.Range(0, 100) > obstacleChance) return -2;
|
||||
|
||||
var lane = Random.Range(-1, 2);
|
||||
var spawnPos = new Vector3(lane * laneDistance, 0, zPos);
|
||||
@@ -86,9 +90,26 @@ namespace Code.Gameplay.Level
|
||||
var obs = Instantiate(prefab, spawnPos, Quaternion.Euler(0, 180, 0));
|
||||
obs.transform.SetParent(_activeTiles[^1].transform);
|
||||
}
|
||||
|
||||
return lane;
|
||||
}
|
||||
|
||||
private void SpawnCoins(float zPos, int occupiedLane)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
var spawnPos = new Vector3(coinLane * laneDistance, 1f, zPos + (i * 2f));
|
||||
var coin = Instantiate(coinPrefab, spawnPos, Quaternion.identity);
|
||||
coin.transform.SetParent(_activeTiles[^1].transform);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject GetRandom(GameObject[] array)
|
||||
private static GameObject GetRandom(GameObject[] array)
|
||||
{
|
||||
return array.Length > 0 ? array[Random.Range(0, array.Length)] : null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user