private void InitObjectPool() { for (int i = 0; i < objectPrefabs.Length; i++) { GameObject newObj = Instantiate(objectPrefabs[i], transform); newObj.SetActive(false); ObjectScrollBehaviour obj = newObj.GetComponent <ObjectScrollBehaviour>(); obj.Init(layerScrollIndex, color, startPointPosition, endPointPosition, layerScrollSpeed); objectPool.Add(obj); } }
private void Update() { if (isPause.Value) { return; } if (lastObject.transform.position.x + lastObject.GetWidth() + layerScrollGapSize <= startPointPosition.x) { lastObject = GetRandomObject(); lastObject.transform.position = startPointPosition; lastObject.gameObject.SetActive(true); } }
private void OnEnable() { InitObjectPool(); lastObject = GetRandomObject(); lastObject.gameObject.SetActive(true); }