Hi,
ok, I created a working sample for this type of game. This is the basic logic, you will have to handle the creation of road items.
WARNING: for efficiency, you might find that using a pool manager will give you better performances, especially on mobile. Here this is just a sample to show you the basic logics behind creation and management of endless roads and the likes.
This sample use two types of system to detect when to trigger an action as the road is moving.
-- modulo operator: as the scene is moving forward, knowing road blocks are 10 units long, I maintain a modulo float that range from 0 to 10 as it moves, which means I always know where I am within the last road block ahead ( 0 at the very beginning, 10 at the very end). I use this modulo to trigger the next road block creation.
-- plain physics trigger. The easiest solution it to maintain a trigger ahead of the camera that would detect when there is no more road. I used this technic to delete previous blocks not visible to the camera anymore. THIS IS CRITICIAL to clean up, otherwise this will leak memory and eventually lead to crash if your play time is long ( you will end up with hundreds of road block, with 99% of it invisible to the camera)
-- also, I have implemented a simple trigger underneath the road to detect when the cube will fall off the road and restart the scene. That's the type of mechanism that can be used to detect when player looses. You can pause the game then, etc etc.
If you have questions, don't hesitates.
Bye,
Jean