Created
August 13, 2022 15:58
-
-
Save Mazday21/e503015d6e97739bee0b24499770f651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
public class RoadSpawner : MonoBehaviour | |
{ | |
[SerializeField] private List<GameObject> _roads; | |
[SerializeField] private Player _player; | |
private float _roadLenght = 89.6f; | |
private void OnEnable() | |
{ | |
_player.TriggerRoadEntered += LayRoad; | |
} | |
private void OnDisable() | |
{ | |
_player.TriggerRoadEntered -= LayRoad; | |
} | |
private void Start() | |
{ | |
_roads = _roads.OrderBy(r => r.transform.position.z).ToList(); | |
} | |
private void LayRoad() | |
{ | |
GameObject movedRoad = _roads[0]; | |
_roads.Remove(movedRoad); | |
float newPositionZ = _roads[_roads.Count - 1].transform.position.z + _roadLenght; | |
movedRoad.transform.position = new Vector3(0, 0, newPositionZ); | |
_roads.Add(movedRoad); | |
Debug.Log("LayRoad"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment