2D Galaxy Shooter: New Enemy Movement…..!!
Enable the Enemies to move in a new way, either from side to side, circling…
As per my last article on ScriptableObjects, we can use that concept and make enemy movement in a new way….
First we create an empty GameObject -Path(0) and under this create another empty GameObject — WayPoint(0) assign a diamond symbol by selecting icons as shown below..i.e, create a duplicate and assigned it WayPoint(1), WayPoint(2), WayPoint(3) etc and placed at different positions on the scene where one desire to move an enemy from one position to another -which can though to be as a new enemy movement……
Path(0) — we can use this as Prefab - a reusable component as shown below.
Now under Wave folder Wave1 — we can assign Properties such as Path(0) & Enemy Prefab that we have created.
In SpawnManager.cs script — define variables _waveConfig and _startingWave , so that we can reference in inspector and assign Wave1 to it as shown below.
From here we can create a coroutine to SpawnAllWaves- here we have only one wave Wave1.Until Player is not dead, we keep looping for the waves and in each wave we can loop all the enemies using another coroutine passing current wave SpawnAllEnemiesInWave(currentWave) and instantiate new enemies using enemy prefab-using waveConfig.GetEnemyPrefab() as well as get the position using waveConfig.GetWayPoint()[0].transform position that we assign from WaveConfig,cs file
From here communicate to Enemy.cs script reference the waveConfig (where new enemy movement gets called..) , make new enemy setActive and when enemies instantiated they are placed under the SpawnManager/EnemyContainer.
Enemy.cs script with new movement having new waypoints mentioned in below script…