private void Start() { if (_obstaclePool == null) { _obstaclePool = FindObjectOfType <ObstaclePool>(); } if (_highwayPool == null) { _highwayPool = FindObjectOfType <HighwayPool>(); } if (_particlePool == null) { _particlePool = FindObjectOfType <ParticlePool>(); } _chunkSize = (int)(_chunkSize / _highwayPool.HighwayPieceLength) * _highwayPool.HighwayPieceLength; _chunkSpawnCheckpoint = GetComponent <BoxCollider>(); _chunkSpawnCheckpoint.isTrigger = true; _chunkSpawnCheckpoint.center = new Vector3(0, 0, _chunkSize); CreateChunk(1, true); CreateChunk(2, false); }
private void SpawnObject() { GameObject objectToSpawn = ObstaclePool.Instance(ObjectNames.Obstacle1); objectToSpawn.transform.position = Vector3.right * 5; }
void Start() { //initialize members instance = this; objectPools = new GameObject[obstacleList.Length, poolSize]; cycleIndexes = new int[obstacleList.Length]; PoolObjects(); }
private void Start() { player = PlayerController.Instance; pool = ObstaclePool.Instance; ground = GameObject.FindGameObjectWithTag("Ground"); lines = new List <float>(player.getLinePositionX()); calledObjects = new List <GameObject>(); ground.SetActive(false); }
public void SpawnChunk(float chunkLength, ObstaclePool obstaclePool, HighwayPool highwayPool, ParticlePool particlePool, bool firstChunk) { _chunkLength = chunkLength; ChunkCenter = transform.position; _obstaclePool = obstaclePool; _particlePool = particlePool; _highwayPool = highwayPool; SpawnHighway(); SpawnObstacles(firstChunk); }
private void Awake() { if (ObstacleInstance == null) { ObstacleInstance = this; } else if (ObstacleInstance != this) { Destroy(gameObject); } }
// Use this for initialization void Start() { //Set the list of audioClips in a stack used by the Obstacles reshuffle(audioSourcesList); ObstacleSpawner.obstacleAudio = new Queue <AudioClip>(this.audioSourcesList); //Get pool this.pool = GameObject.FindObjectOfType <ObstaclePool>().GetComponent <ObstaclePool>(); //Start the coountdown for the spawns. StartCoroutine(waitAndSpawn(0.5f)); }
private void Start() { var generatedObjects = GameObject.Find("GeneratedObjects"); var initialCoord = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height)); generationHight = initialCoord.y * 1.3f; halfRange = initialCoord.x * 2; generationRangeLeft = -halfRange; generationRangeRight = halfRange; pools = new ObstaclePool[obstacles.Length]; for (var i = 0; i < obstacles.Length; i++) { pools[i] = new ObstaclePool(obstacles[i], poolCount, generatedObjects.transform); } gameManager = GameManager.Instance; }
public void AssignPoolValuesWithLibrary() { foreach (EnemyPool pool in enemiesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } foreach (ObstaclePool pool in obstaclesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } foreach (ProjectilePool pool in projectilesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } enemiesPools = new List <EnemyPool>(); obstaclesPools = new List <ObstaclePool>(); projectilesPools = new List <ProjectilePool>(); LevelPrefabsLibrary levelPrefabsLibrary = Resources.Load("Level Prefabs Library") as LevelPrefabsLibrary; if (levelPrefabsLibrary == null) { Debug.LogError("Library Not Found"); return; } List <LevelPrefabInformations> enemiesInformations = levelPrefabsLibrary.GetEnemyPrefabInformations; for (int i = 0; i < enemiesInformations.Count; i++) { LevelPrefabInformations info = enemiesInformations[i]; if (info.elementPrefab == null) { continue; } EnemyPool newEnemyPool = new EnemyPool(); int index = 200 + i; newEnemyPool.elementLibraryIndex = index; newEnemyPool.enemyPrefab = info.elementPrefab.GetComponent <EnemySpaceShipScript>(); newEnemyPool.instantiatedObjects = new List <EnemySpaceShipScript>(); newEnemyPool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newEnemyPool.poolParent = parent.transform; enemiesPools.Add(newEnemyPool); } List <LevelPrefabInformations> obstaclesInformations = levelPrefabsLibrary.GetObstaclePrefabInformations; for (int i = 0; i < obstaclesInformations.Count; i++) { LevelPrefabInformations info = obstaclesInformations[i]; if (info.elementPrefab == null) { continue; } ObstaclePool newObstaclePool = new ObstaclePool(); int index = 100 + i; newObstaclePool.elementLibraryIndex = index; newObstaclePool.obstaclePrefab = info.elementPrefab.GetComponent <Obstacle>(); newObstaclePool.instantiatedObjects = new List <Obstacle>(); newObstaclePool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newObstaclePool.poolParent = parent.transform; obstaclesPools.Add(newObstaclePool); } List <LevelPrefabInformations> projectileInformations = levelPrefabsLibrary.GetProjectilePrefabInformations; for (int i = 0; i < projectileInformations.Count; i++) { LevelPrefabInformations info = projectileInformations[i]; if (info.elementPrefab == null) { continue; } ProjectilePool newProjectilePool = new ProjectilePool(); int index = 300 + i; newProjectilePool.elementLibraryIndex = index; newProjectilePool.projectilePrefab = info.elementPrefab.GetComponent <ProjectileScript>(); newProjectilePool.projectilePrefab.SetPoolingIndex(index); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(newProjectilePool.projectilePrefab); #endif newProjectilePool.instantiatedObjects = new List <ProjectileScript>(); newProjectilePool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newProjectilePool.poolParent = parent.transform; projectilesPools.Add(newProjectilePool); } #if UNITY_EDITOR UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene); #endif }
private void Awake() { GrowPool(); instance = this; }
void Start() { this.pool = GameObject.FindObjectOfType <ObstaclePool>().GetComponent <ObstaclePool>(); }
private void Awake() { pool = this; }
// Use this for initialization void Start() { //Initial Position this.transform.position = middleLanePos; this.pool = GameObject.FindObjectOfType <ObstaclePool>().GetComponent <ObstaclePool>(); }