AwesomeRunner/Assets/Scripts/Road/ChunkGenerator.cs
PC-PAUL\paulf 08338d6dc7 Merge branch '1vs1' into dev
# Conflicts:
#	Assets/Scenes/DeathScreen.unity
#	Assets/Scenes/MainMenu.unity
#	Assets/ScriptableObjects/PlayerData.cs
#	Assets/Scripts/GameSession/GameSession.cs
#	Assets/Scripts/Player/Player.cs
#	Assets/Scripts/Road/ChunkGenerator.cs
2025-01-15 09:51:22 +01:00

42 lines
1.5 KiB
C#

using Pools;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChunkGenerator : MonoBehaviour
{
[SerializeField] private LaneSystem LaneSystem;
public CoinPool CoinPool { get; private set; }
[field: SerializeField] public List<ObstaclePool> ObstaclePools { get; private set; }
private bool _isFirstChunk = true;
public Chunk Generate(Chunk chunkToFill)
{
if (_isFirstChunk)
{
_isFirstChunk = false;
return chunkToFill;
}
if (ObstaclePools.IsEmpty())
return chunkToFill;
var obstaclePool = ObstaclePools.GetRandomElement();
var obstacle = obstaclePool.Spawn();
chunkToFill.Obstacles.Add(obstacle);
obstacle.transform.SetParent(chunkToFill.transform, true);
obstacle.transform.localPosition = chunkToFill.Grid.GetRandomPosition();
if (obstacle.IsOnAllLanes)
{
obstacle.transform.localPosition = new Vector3(
LaneSystem.CenterLane * LaneSystem.LaneWidth,
transform.localPosition.y,
transform.localPosition.z
);
//TODO: A enlever (pour fix bug)
// if (obstacle.IsOnAllLanes)
// {
// obstacle.transform.localPosition = new Vector3(LaneSystem.CenterLane * LaneSystem.LaneWidth, transform.localPosition.y, transform.localPosition.z);
// }
}
return chunkToFill;
}
}