The long Day Finished

Today I was very focused on a few things that were challenging and took quite a bit of time to figure out. I started the day off with the “Effects” section of the 2D course. This consisted of creating an explosion for our enemy upon death, giving us a giant asteroid to shoot that would then trigger all of our enemies and power ups to start appearing, and then finishing off with the animation of said asteroid and the player upon death. The first, animating the enemy explosion was fairly simple, and in order to do this you would first create an animation sequence for the game object. Once this is done you need to tell the game object about this sequence in the script. Since the enemy and player scripts are talking to each other we need to create local variables for the animation and for the player on the enemy script, then use the “_localVariable = GameObject.Find()GetComponent<>();” to find our player script and assign it to out local variable. Now that we have done that when we use our “_localVariable” it is actually calling upon the Player script that we had it go find. With this information we can access anything public on the players script and use it. But for this instance we are just accessing the player itself, as we just want the animation to start when we have been “hit” by a laser or by the player. Then we explode in a fire ball of awesomeness.

From there I proceeded to spend way to much time working on the movement of my asteroid. The challenge was to make it rotate in one direction while being stationary, but I wanted it to also move down. I could get it to move down easily enough using “transform.Translate(Vector3.down * _speed * Time.deltaTime);” which works beautifully. but then adding the rotation was quite challenging. I was struggling to get it to move down on the “y” axis only while rotating. What I ended up doing was creating a empty game object that acted as the “Parent” for the asteroid itself. I then attached the asteroid to the parent object, and created the rotation on the asteroid, and wrote a script for the Parent to move down. In the end I put most of the functionality on the parent object because when you destroy the “Parent” object in a game you also destroy the child. So when our asteroid exploded it was really gone.

Post Processing

After that I wrote a quick method on our “Spawn Manager” called “Public Void Start Spawning” and moved all of our start coroutine stuff into that. This enables us to call upon the spawn manage when we wanted it to start spawning. When my asteroid explodes we simply call upon that and then our enemies will start appearing. I finished the day off playing around with the post processing and then adding in some game audio. Most of the code used for this was what we had already been using, assign local variable, get component, and then tell it when to be active. Of course you also need to [SerializeField] so you can enable the component in the inspector. I was very successful with adding all of the game audio so far, including my explosion sounds, the laser and power up sounds, along with our sweet game music itself. I do want to make my power up sound louder though, so I might play with that a little more today. Now to just finish the game and make it ready for the world!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Joe Kuka

Joe Kuka

I am a self taught game developer and love pushing myself to learn new things.