AwesomeRunner/Assets/Scripts/Road/ChunkGenerator.cs
VladimirPirozhenko 9067758171 Extracted code to Grid class, adjusted jump time to get better game feel
Also fixed scaling of score ui element
2022-08-14 06:14:54 +03:00

27 lines
1004 B
C#

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; }
public Chunk Generate(Chunk chunkToFill)
{
if (ObstaclePools.IsEmpty())
return chunkToFill;
var obstaclePool = ObstaclePools.GetRandomElement();
var obstacle = obstaclePool.GetFromPool();
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);
}
return chunkToFill;
}
}