public void CreateBar(double tick) { if (nextBar < tick + MetersToTickDistance(4f)) //spawn tick + 10 seconds? { BarInstance newBar = pool.bar[index.bar % pool.barSize]; index.bar++; newBar.gameObject.SetActive(true); newBar.timestamp = nextBar; activeBars.Add(newBar); nextBar += resolution; } }
public void UpdateActiveBars(double smoothTick) { for (int i = 0; i < activeBars.Count; ++i) { BarInstance barInstance = activeBars[i]; double tickDistance = barInstance.timestamp - smoothTick; double distanceInMeters = TickDistanceToMeters(tickDistance); Vector3 pos = barInstance.myTransform.localPosition; pos.z = (float)distanceInMeters; barInstance.myTransform.localPosition = pos; if (tickDistance < 0) { willRemoveBars.Add(barInstance); } } for (int i = willRemoveBars.Count - 1; i > -1; --i) { activeBars.Remove(willRemoveBars[i]); willRemoveBars[i].gameObject.SetActive(false); willRemoveBars.RemoveAt(i); } }