Day 3 and 4 — Shooting Tic-tac's and Spawning Cubes

After some hectic days I finally get around to writing this up. The fun part of this course. The title might be a bit misleading but I managed to get the systems for spawning the enemies and the player shooting lasers up and running. Though there will be some tweaks as I go but the overarching systems are up and running.
The first system, getting the player to shoot. Getting the player to shoot some lasers wasn’t that hard and it’s just some simple Instantiation (Creation) of a Gameobject and getting said object to move.

This code here is just a simple fire method. It gives it a cooldown, using the Fire Rate and Time.time (which is how long the game has been running) and adds that to another Float value to allow for said cooldown time. The Fire Point position is just an empty gameobject that I’m using as a reference for where I want the laser to spawn.
Enemy Spawning and Waves:
The way I decided to do this was using Scriptable Objects. A scriptable object is a Unity Specific data container. That’s all it is — a fancy way to allow for easy access to some data.

In this I made the system really simple. It’s a simple List of Gameobjects that I can access to allow for myself to make a wave that can be edited the way I want.
Now, some of you might be wondering, what does the CreateAssetMenu Attribute do? This attribute is one way of extending the Unity Editor, but more on that later, this one is really simple in the sense of it allows you to add a way to make your Scriptable object when you right click.

I have a new menu item in my right click called “Scriptable Objects” and inside that is my scriptable object name “Wave”. As I said a fancy data container. This ties into how I decided to make my SpawnManager System.

Doing Two things here
- I have a List of my Wave scriptable object.
- I decided to get Object Pooling up and running for this. Object pooling is a way to keep objects without having to constantly create new ones after destroying them. You keep them in the engine and have quicker access to them because they won’t have to be created anew when needed.

Hope this has brought attention to Scriptable Objects and Object Pooling, because they’re both useful in many different ways.
With that though, it’s on to the next. Time to get that Spawn Manager fixed and finished. Day 5 is going to be a fun day.