
Above is the script I've replaced the old PrefabSpawner script with, if anyone's curious. It's a pretty simple script containing two methods:
Spawn(GameObject gameObject) does exactly what it's name implies, instantiates (spawns) a copy of whichever game object is passed into the gameObject argument (everywhere I've used it uses prefab objects in my project directory but it's theoretically possible to use existing objects in the scene I now realize!) at the position and rotation of the spawner. If you read the method in the screenshot, you'll probably see it also sets the private boolean member spawnFlag, which is used for the second method, to true.
GetHasSpawned effectively returns true if the spawner has spawned a game object since the last call to GetHasSpawned. How it does so is fairly self-explanatory if you read the method above. This exists solely to be read by the script handling the bullet firing animations and SFX which triggers both of those when the bullet spawners attached to the player and enemies spawn bullets by checking GetHasSpawned's return value once per frame update.
The original PrefabSpawner script I had would spawn a predefined prefab when triggered to, and this worked just fine for the bullets (which use the same spawning script as the enemy columns) however, it became counterproductive when I began trying to implement the upcoming beetle enemy. The versatility of this new spawner will make implementing new enemies and furthermore new ammo types (which is something I have planned for the future as well O.O) a lot easier and more intuitive.
0 comments