Game Over Animation And Restarting

Game Over Animation And Restarting

I am putting in all the plumbing to manage the game over state and restarting the game. Now, whenever the player is pushed off the screen I simply slow down time to give the illusion like all the obstacles and animations are stopped. This is such an easy effect plus the TimeManager class will also allow me to pause and unpause the game. Finally, once the game is over I have some logic to clear the screen and spawn a new player. The only issue is that I don’t have a click lock in place so of course I found a good bug by just clicking as many times as I could before the game had officially started. This was a quick one to fix. I just need to make sure I set my game started flag as soon as the first player is...
Adding Jumping To My Unity 2D Game

Adding Jumping To My Unity 2D Game

My endless runner is shaping up nicely. I added some simple behaviors to the player now. He can jump over obstacles and when one hits him, he gets pushed off the screen. Also the player can land on an obstacle which will stop the running animation and also carry him off the screen. The next steps will be to add some zombies at the left hand side of the screen, so when the player gets pushed offscreen he is eaten by a mob of...
My 2D Sprite Pipeline for Unity

My 2D Sprite Pipeline for Unity

At this point I have the perfect pipeline setup for building 2D games in Unity. I start with a PhotoShop template that has all my sprite layers in it. In this case the player is made up of details (the topmost layer), body and legs. This lets me change the color of any layer on the fly in Unity plus I can switch out between weapons for the body animation as well. Here is what that template looks like: From here I use a script I found on GitHub that exports the layers to pngs. This script is a lot faster than the one that ships with PS and also lets me use the layer name as the file name which cuts out a step of renaming my files. From here I use Texture Packer to combine all the individual sprites into a texture atlas. Then I use the free Texture Packer Unity plugin which automatically converts the texture atlas into sprites whenever you update the file outside of Unity. And when I’m done I get all my sprites cut up and named for me automatically. The best part is that I can continue to update the sprites as I tweak all the artwork throughout my dev cycle and everything stays in sync. Then at the end, I can use Unity Pro’s packer feature to turn all my individual texture atlases into more optimized ones for better performance when I publish my...
Simple Pooling for GameObjects in Unity

Simple Pooling for GameObjects in Unity

Turns out adding in Object Pooling isn’t as easy as I would have hoped. Most of my issues turned out to revolve around not being able to access interfaces directly on GameObjects. Here is a quick sample of my final object pooling running: As you can see I am now spawning objects and each one is created from scratch, assuming there isn’t an instance already in the scene. The key here is that when a GameObject runs off the screen I disable it by looking for the following script: using UnityEngine; using System.Collections;   public class RecycleGameObject : MonoBehaviour, IRecycle {   public virtual void Reset(){ gameObject.SetActive(true); }   public virtual void Dissable(){ gameObject.SetActive(false); } }using UnityEngine; using System.Collections; public class RecycleGameObject : MonoBehaviour, IRecycle { public virtual void Reset(){ gameObject.SetActive(true); } public virtual void Dissable(){ gameObject.SetActive(false); } } Now my Objects imply implement this script and override the two methods Reset and Dissable to achieve the desired results. Now when an object goes offscreen, I request the RecycleGameObject script like so: void OnOutOfBounds(){   var recycleScript = GetComponent<RecycleGameObject> ();   if (recycleScript == null) { Destroy (gameObject); } else { recycleScript.Dissable(); } }void OnOutOfBounds(){ var recycleScript = GetComponent<RecycleGameObject> (); if (recycleScript == null) { Destroy (gameObject); } else { recycleScript.Dissable(); } } To my surprise, looking for RecycleGameObject components also return any component that extends it so now I can easily shut down an object offscreen and my pool class returns any disabled instances from its...
Changing BoxCollider2D Size Based On Sprite Size

Changing BoxCollider2D Size Based On Sprite Size

Now that I have some objects randomly being generated I need to make sure that the BoxCollider2D matches the size of the sprite. I am cheating a little bit since all of my objects are boxes but here you can see how I go from the desk: To the dresser: To the crate: And they are all the same exact prefab, randomly picking a sprite from this array: The code is really simple, it’s actually only a few lines: var renderer = GetComponent<spriterenderer> (); renderer.sprite = sprites [Random.Range(0, sprites.Length)];   // Change collider to match the size of the sprite var collider = GetComponent<boxcollider2d> (); collider.size = renderer.bounds.size;var renderer = GetComponent<spriterenderer> (); renderer.sprite = sprites [Random.Range(0, sprites.Length)]; // Change collider to match the size of the sprite var collider = GetComponent<boxcollider2d> (); collider.size =...

Subscribe To My Mailing List

Want to learn how to make a game? Not sure where to start? Even if you are a seasoned game maker there is still a lot you can learn from my mailing list. I'll be covering tips and tricks for how to build, release and market games each month.

Simply sign up for my mailing list and also get access to a 50% off discount code for my eBooks and other content. I promise to not spam your inbox!

Join Now