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.

86 lines
2.0 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. 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. private int m_bendProfile = 0;
  11. private TileController m_previousTile;
  12. private TileController m_currentTile;
  13. public enum TileTypes
  14. {
  15. BEND_LEFT = -1,
  16. STRAIGHT = 0,
  17. BEND_RIGHT = 1,
  18. };
  19. private void Start()
  20. {
  21. m_currentTile = FindObjectOfType<TileController>();
  22. for (int i = 0; i < trackTiles; i++)
  23. {
  24. SpawnRandomTile();
  25. }
  26. }
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. /*
  31. if (m_previousTile != null)
  32. {
  33. if (Vector3.Distance(m_previousTile.transform.position, Camera.main.transform.position) > m_exitCullDistance)
  34. {
  35. Destroy(m_previousTile);
  36. m_previousTile = null;
  37. }
  38. }
  39. */
  40. /*if(Input.GetKeyDown(KeyCode.Space))
  41. {
  42. SpawnRandomTile();
  43. }*/
  44. }
  45. void SpawnRandomTile()
  46. {
  47. var _startBendProfile = m_bendProfile;
  48. TileData _selectedTile = new TileData();
  49. do
  50. {
  51. _selectedTile = m_tileList[Random.Range(0, m_tileList.Count - 1)];
  52. }
  53. while (Mathf.Abs(m_bendProfile + (int)_selectedTile.tileType) >= 2);
  54. m_bendProfile += (int)_selectedTile.tileType;
  55. var _newTileObj = Instantiate(_selectedTile.prefab);
  56. _newTileObj.transform.forward = m_currentTile.exitAnchor.transform.forward;
  57. var _newTileController = _newTileObj.GetComponent<TileController>();
  58. Vector3 _offset = m_currentTile.exitAnchor.position - _newTileController.entryAnchor.position;
  59. _newTileObj.transform.position += _offset;
  60. m_previousTile = m_currentTile;
  61. m_currentTile = _newTileController;
  62. }
  63. }