Question by
keeermitfroge · May 10, 2020 at 01:17 PM ·
c#object pooltrain
Object Pooling causing a gap between last and first reused tile in array
I am making a train platformer game where the train is stationary and the rails,background move around it. So the problem is when the track pieces regenerate the last tile and the reused first tile create a large gap in between. I cant really figure it out.
[SerializeField]
private GameObject[] platformPrefabs;
public float offset;
[SerializeField]
public int xOffset;
public int addedOffset;
private void Start()
{
for (int i = 0; i < platformPrefabs.Length; i++)
{
Instantiate(platformPrefabs[i], new Vector3(i * offset, 0, 0), Quaternion.identity);
xOffset += addedOffset;
}
}
public void Recycle(GameObject platform)
{
platform.transform.position = new Vector3(platformPrefabs.Length * offset, 0, 0);
//xOffset += addedOffset;
}
Comment