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

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TileManager : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private List<TileData> m_tileList = new List<TileData>();
  8. [SerializeField]
  9. private int trackTiles = 10;
  10. [SerializeField]
  11. private TileData m_finalTile;
  12. private int m_bendProfile = 0;
  13. private TileController m_previousTile;
  14. private TileController m_currentTile;
  15. public enum TileTypes
  16. {
  17. BEND_LEFT = -1,
  18. STRAIGHT = 0,
  19. BEND_RIGHT = 1,
  20. };
  21. private void Start()
  22. {
  23. m_currentTile = FindObjectOfType<TileController>();
  24. for (int i = 0; i < trackTiles; i++)
  25. {
  26. SpawnTile();
  27. }
  28. SpawnTile(m_finalTile);
  29. }
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. /*
  34. if (m_previousTile != null)
  35. {
  36. if (Vector3.Distance(m_previousTile.transform.position, Camera.main.transform.position) > m_exitCullDistance)
  37. {
  38. Destroy(m_previousTile);
  39. m_previousTile = null;
  40. }
  41. }
  42. */
  43. /*if(Input.GetKeyDown(KeyCode.Space))
  44. {
  45. SpawnRandomTile();
  46. }*/
  47. }
  48. /// <summary>
  49. /// Spawn next tile
  50. /// </summary>
  51. /// <param name="tileData">Leave null for random</param>
  52. void SpawnTile(TileData tileData = null)
  53. {
  54. var _startBendProfile = m_bendProfile;
  55. TileData _selectedTile = tileData;
  56. if(_selectedTile == null)
  57. {
  58. do
  59. {
  60. _selectedTile = m_tileList[Random.Range(0, m_tileList.Count - 1)];
  61. }
  62. while (Mathf.Abs(m_bendProfile + (int)_selectedTile.tileType) >= 2);
  63. }
  64. m_bendProfile += (int)_selectedTile.tileType;
  65. var _newTileObj = Instantiate(_selectedTile.prefab);
  66. _newTileObj.transform.forward = m_currentTile.exitAnchor.transform.forward;
  67. var _newTileController = _newTileObj.GetComponentInChildren<TileController>();
  68. Vector3 _offset = m_currentTile.exitAnchor.position - _newTileController.entryAnchor.position;
  69. _newTileObj.transform.position += _offset;
  70. m_previousTile = m_currentTile;
  71. m_currentTile = _newTileController;
  72. }
  73. }