- Home /
Endless runner track script
Hi guys,
i'm trying to get better and better in unity, right now im creating an endless runner game to practice.
I want your opinion on the script i just created to create the track.
public class TrackManager : MonoBehaviour {
public GameObject tileOne;
public GameObject tileTwo;
public GameObject tileThree;
public GameObject tileFour;
public GameObject player;
public float tileDepth;
void Update()
{
if(player.transform.position.z > tileThree.transform.position.z)
{
GameObject newTileOne = tileFour;
newTileOne.transform.position = new Vector3(tileOne.transform.position.x, tileOne.transform.position.y, tileOne.transform.position.z + tileDepth);
tileFour = tileThree;
tileThree = tileTwo;
tileTwo = tileOne;
tileOne = newTileOne;
}
}
}
What i do is rather easy. I create by default 4 tiles in my scene, making them long enough (Z axis) so three of them fill atleast the range of my camera. As you can see in my script i just place the last one in front of the first one and so on.
This means i reuse my tiles, i think thats good practice?
However when i start walking i ofcourse notice that my players Z axis point is increasing the further i walk. If a player of my game is very good and he reaches very far that Z axis point will be so long i can't even imagine. Is that a problem? Or is that not a problem as long as i make sure i destory all game objects behind me (out of camera view).
Thanks!
Your answer
Follow this Question
Related Questions
Player movement for iOS? 1 Answer
can anyone find the issue with this code? 2 Answers
Multiple Camera Angles, Choseable 1 Answer
How can i smooth out the rotation? 1 Answer