Track - Unity-Technologies/EndlessRunnerSampleGame GitHub Wiki

The way the game build the game track is by using TrackSegement it spawn one after another, removing them when they arrive behind the player.

TrackSegment

The TrackSegment script define a single track segment. It is placed on the 3D mesh defining that piece of track (i.e. containing the road and side decorative pieces).

It got a Path child GameObject (assigned to the Path Parent property of the TrackSegment script) that itself have (at least 2) GameObject children that form the path of that segment.

All the track segments in the base game have just an entry and exit node, forming a straight line, but we could potentially make more complex path that are moving at an angle or in a Z shape. Current implementation does not rotate, so all path will always go in the same direction, you can't do "turning" path

TrackSegment have an array of "Possible Obstacle". This is all the prefabs with a script derived from Obstacle (Like SimpleBarricade, PatrollingObstacle...) that can be spawn on that track segment.

Finally it got a list of Obstacles position. Clicking "Add Obstacle" add a new lines, clicking the "-" next to a line remove it. The range value next is the position on the path (between 0 and 1) where the obstacle will be place.

E.g : A track segment having 3 Possible Obstacles (SimpleBarricade, PatrollingObstacle and AllLaneObstacle) and 2 Obstacle position, one at 0.5 and one at 0.75, will, when it's spawn, pick randomly one of the possible obstacle and place it in the middle of the segment path, and pick another one randomly to place at 3/4 of the path length.

ThemeData and Zones

The ThemeData (see the page on how to create a theme for more information on Theme Data and what it does) define multiple list of TrackSegement called "Zones"

The TrackManager that handle spawning the TrackSegment will start with the first "Zone". Taking one track segment from that list randomly and adding it to the track. It will continue until it reach the "Length" of the zone (define per zone in the ThemeData). It will then go to the next zone and continue until reaching the last zone. At that point, it will loop back to the first zone etc.

E.g. the base game have 3 zone, 500 units (meters) long each. The first is Industrial building, the second Suburbans and the third City building. The gram will start spawning Industrial track piece for the first 500 meters, then switch to suburban and finally city, until going back to industrial