|
|
@ -10,6 +10,9 @@ public class TileManager : MonoBehaviour |
|
|
|
[SerializeField] |
|
|
|
private int trackTiles = 10; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private TileData m_finalTile; |
|
|
|
|
|
|
|
|
|
|
|
private int m_bendProfile = 0; |
|
|
|
|
|
|
@ -30,10 +33,10 @@ public class TileManager : MonoBehaviour |
|
|
|
|
|
|
|
for (int i = 0; i < trackTiles; i++) |
|
|
|
{ |
|
|
|
SpawnRandomTile(); |
|
|
|
SpawnTile(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SpawnTile(m_finalTile); |
|
|
|
} |
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
@ -58,23 +61,30 @@ public class TileManager : MonoBehaviour |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
void 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 = new TileData(); |
|
|
|
TileData _selectedTile = tileData; |
|
|
|
|
|
|
|
do |
|
|
|
if(_selectedTile == null) |
|
|
|
{ |
|
|
|
_selectedTile = m_tileList[Random.Range(0, m_tileList.Count - 1)]; |
|
|
|
do |
|
|
|
{ |
|
|
|
_selectedTile = m_tileList[Random.Range(0, m_tileList.Count - 1)]; |
|
|
|
} |
|
|
|
while (Mathf.Abs(m_bendProfile + (int)_selectedTile.tileType) >= 2); |
|
|
|
} |
|
|
|
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.GetComponent<TileController>(); |
|
|
|
var _newTileController = _newTileObj.GetComponentInChildren<TileController>(); |
|
|
|
|
|
|
|
Vector3 _offset = m_currentTile.exitAnchor.position - _newTileController.entryAnchor.position; |
|
|
|
_newTileObj.transform.position += _offset; |
|
|
|