コード例 #1
0
        private void SpawnWallColumns()
        {
            var wallColumn = wallColumnPool.GetItem();

            wallColumn.Spawn(Vector2.left * MapController.Singleton.PlayerSeeRadius, new Vector2(0, MapController.Singleton.ScreenHeight), new Vector2(0, -MapController.Singleton.ScreenHeight));
            lastSpawnedWallColumn = wallColumn;

            while (lastSpawnedWallColumn.transform.position.x < MapController.Singleton.PlayerSeeRadius)
            {
                wallColumn = wallColumnPool.GetItem();

                wallColumn.Spawn(lastSpawnedWallColumn.transform.position + Vector3.right, new Vector2(0, MapController.Singleton.ScreenHeight), new Vector2(0, -MapController.Singleton.ScreenHeight));
                lastSpawnedWallColumn = wallColumn;
            }
        }
コード例 #2
0
        private IEnumerator Move()
        {
            while (isPlaying)
            {
                Vector3 delta = new Vector2(moveSpeed * Time.deltaTime, 0f);

                foreach (var wallColumn in wallColumnPool.ActiveItems)
                {
                    wallColumn.transform.position -= delta;

                    if (wallColumn.transform.position.x < -MapController.Singleton.PlayerSeeRadius)
                    {
                        wallColumnPool.PoolItem(wallColumn);
                    }
                }

                bool scorePointSpawned = false;

                while (lastSpawnedWallColumn.transform.position.x < MapController.Singleton.PlayerSeeRadius)
                {
                    var wallColumn = wallColumnPool.GetItem();

                    wallColumn.Spawn(lastSpawnedWallColumn.transform.position + Vector3.right, Vector2.zero, Vector2.zero);
                    wallColumn.OpenCloseColumn(true);
                    lastSpawnedWallColumn = wallColumn;

                    if (!scorePointSpawned && scorePointSpawnChance >= Random.value && scorePointPool.HasAvailableItems)
                    {
                        var scorePoint = scorePointPool.GetItem();
                        scorePoint.transform.position = new Vector3(lastSpawnedWallColumn.transform.position.x, Random.Range(-MapController.Singleton.ScreenHeight / 2f, MapController.Singleton.ScreenHeight / 2f));

                        scorePointSpawned = true;
                    }
                }

                foreach (var scorePoint in scorePointPool.ActiveItems)
                {
                    scorePoint.transform.position -= delta * 0.5f;

                    if (scorePoint.transform.position.x < -MapController.Singleton.PlayerSeeRadius)
                    {
                        scorePointPool.PoolItem(scorePoint);
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }