Global Game Jam 2023
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TileManager : MonoBehaviour
{
[SerializeField]
private List<TileData> m_tileList = new List<TileData>();
[SerializeField]
private int trackTiles = 10;
[SerializeField]
private TileData m_finalTile;
private int m_bendProfile = 0;
private TileController m_previousTile;
private TileController m_currentTile;
public enum TileTypes
{
BEND_LEFT = -1,
STRAIGHT = 0,
BEND_RIGHT = 1,
};
private void Start()
{
m_currentTile = FindObjectOfType<TileController>();
for (int i = 0; i < trackTiles; i++)
{
SpawnTile();
}
SpawnTile(m_finalTile);
}
// Update is called once per frame
void Update()
{
/*
if (m_previousTile != null)
{
if (Vector3.Distance(m_previousTile.transform.position, Camera.main.transform.position) > m_exitCullDistance)
{
Destroy(m_previousTile);
m_previousTile = null;
}
}
*/
/*if(Input.GetKeyDown(KeyCode.Space))
{
SpawnRandomTile();
}*/
}
/// <summary>
/// Spawn next tile
/// </summary>
/// <param name="tileData">Leave null for random</param>
void SpawnTile(TileData tileData = null)
{
var _startBendProfile = m_bendProfile;
TileData _selectedTile = tileData;
if(_selectedTile == null)
{
do
{
_selectedTile = m_tileList[Random.Range(0, m_tileList.Count - 1)];
}
while (Mathf.Abs(m_bendProfile + (int)_selectedTile.tileType) >= 2);
}
m_bendProfile += (int)_selectedTile.tileType;
var _newTileObj = Instantiate(_selectedTile.prefab);
_newTileObj.transform.forward = m_currentTile.exitAnchor.transform.forward;
var _newTileController = _newTileObj.GetComponentInChildren<TileController>();
Vector3 _offset = m_currentTile.exitAnchor.position - _newTileController.entryAnchor.position;
_newTileObj.transform.position += _offset;
m_previousTile = m_currentTile;
m_currentTile = _newTileController;
}
}