I am making an infinite driving game and created a script to create road forward as the current road is seen. For some reason the roads keep duplicating underneath themselves as well as forward and this crashes the game after only a few minutes, any help you can provide would be much appreciated.
public GameObject road;
void OnBecameInvisible()
{
Destroy(gameObject);
}
void OnBecameVisible()
{
GameObject e = Instantiate(road, transform.position + transform.up * 15, transform.rotation) as GameObject;
}
↧