public void Init(Vector2 dir, AsteroidData asteroidData) { this.AsteroidData = asteroidData; _moveDirection = dir; _moveSpeed = Random.Range(asteroidData.minSpeed, asteroidData.maxSpeed); healthComponent.RefillLive(GameEntityTag.UNKNOWN); _currentVelocity = _moveDirection * _moveSpeed; }
public async UniTask SpawnAsteroid(AsteroidData asteroidData, Vector2 moveDirection, Vector2 spawnPos) { GameObject asteroidGO = await _multiplePrefabMemoryPool.SpawnObject(GetRandomAsteroidPrefab(asteroidData).gameObject, spawnPos); var asteroid = asteroidGO.GetComponent <AsteroidComponent>(); asteroid.Init(moveDirection, asteroidData); _spawnedAsteroids.Add(asteroid); _gameSignals.AsteroidSpawnedSignal.Fire(asteroid); }
public async UniTask SpawnAsteroidAtOutOfScreenPosition(AsteroidData asteroidData) { bool isMinHorizontal = Random.Range(0, 2) == 0; bool isMinVertical = Random.Range(0, 2) == 0; Vector2 baseSpawnPos = Vector2.zero; baseSpawnPos.x = (isMinHorizontal) ? minWorldPos.x : maxWorldPos.x; baseSpawnPos.y = (isMinVertical) ? minWorldPos.y : maxWorldPos.y; Vector2 additionalPos = Vector2.zero; additionalPos.x = Random.Range(minAdditionalWorldPos.x, maxAdditionalWorldPos.x); additionalPos.y = Random.Range(minAdditionalWorldPos.y, maxAdditionalWorldPos.y); Vector2 spawnPos = baseSpawnPos; if (isMinHorizontal) { spawnPos.x -= additionalPos.x; } else { spawnPos.x += additionalPos.x; } if (isMinVertical) { spawnPos.y -= additionalPos.y; } else { spawnPos.y += additionalPos.y; } float speed = Random.Range(1f, 10f); Vector2 moveDirection = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)); if (!isMinHorizontal) { moveDirection.x *= -1; } if (!isMinVertical) { moveDirection.y *= -1; } await SpawnAsteroid(asteroidData, moveDirection, spawnPos); }
private void SpawnWave() { _bookKeepingInGameData.AsteroidCount.Value = 0; var currentStageWave = _asteroidAssetSource.GetStageWaveData(_bookKeepingInGameData.CurrentStage.Value); if (currentStageWave == null) { throw new System.NullReferenceException($"Stage Wave Data null on stage {_bookKeepingInGameData.CurrentStage.Value}"); } int asteroidTypeCount = currentStageWave.SpawnAsteroidDataList.Count; for (int i = 0; i < asteroidTypeCount; i++) { int spawnCount = Random.Range(currentStageWave.SpawnAsteroidDataList[i].MinSpawnCount, currentStageWave.SpawnAsteroidDataList[i].MaxSpawnCount + 1); AsteroidData asteroidData = _asteroidAssetSource.GetAsteroidData(currentStageWave.SpawnAsteroidDataList[i].AsteroidID); for (int j = 0; j < spawnCount; j++) { _asteroidSpawnerSystem.SpawnAsteroidAtOutOfScreenPosition(asteroidData); } } }
public AsteroidComponent GetRandomAsteroidPrefab(AsteroidData asteroidData) { int randomIndex = Random.Range(0, asteroidData.prefabVariants.Length); return(asteroidData.prefabVariants[randomIndex]); }