Grabbing some hard earned spoils from the enemies in our games is rewarding, but it’s even more rewarding to spend that hard earned loot. In order to do that we need to set up a shop for our game.
In part 1 we will look at setting up the Shop in a visual manner. For our purposes we are going to be using a menu (UI Canvas in Unity) to serve as the shop. Other ways exist such as adding new scenes to the game but for our needs the UI Canvas works.
If you have ever played a JRPG…
In an earlier article, I discussed how to create an object that could be collected by a player in your games. Today we are going to make that a little more interesting by making our enemies drop some well deserved loot.
Now that we understand how to create a collectable we need to be able to have the dead enemy drop it, as well as assign it a value based upon the type of enemy that we killed.
This will be accomplished in…
Often in game we need to create behaviors that occur at certain moments during an animation. This might seem like a very difficult task. However once again Unity to the rescue with Animation Events.
An animation event is pretty straight forward. It allows us to trigger a code in script at a key moment in the animation. For example, the spider attack above is triggering the projectile acid using animation Events.
Adding the event is pretty simple. In the Animation Window, select the key frame you want the animation event to occur and hit the highlighted button. This will add…
Yesterday we reviewed the the enemy combat logic and took an in-depth look at the details of the enemies ability to attack the player. Today we will have a look at what happens when the player strikes the enemy.
So the enemy can now dish out damage to the play. But lets look at the combat functions for taking damage.
public void Damage(int damageAmount)
if (!_canBeAttacked) return;
Health -= damageAmount;
if (Health < 1)
_isFighting = false;
_canBeAttacked = false;
The main function in the damage received logic is…
It’s pretty obvious that dungeon crawlers and old school platformers are not very much fun if the enemies pose no threat. So we need to give them the ability to defend themselves against our dubious intentions of eradicating them from the games environments. In this article we will look at doing just that.
Today we will have a look at the enemy script (with any non combat related code removed for clarity. Full code can be found on GitHub, link at the bottom).
public abstract class Enemy : MonoBehaviour, IDamagable
[SerializeField] protected int health…
Over the past couple of days we have looked at adding the ability for the player to swing his weapon. Created a hit box to detect when the enemy was hit, and setup a modular enemy class to use in the combat system.
Today we are going to put all of that together and finally make the enemy appear to take a hit from our players sword. To do this we are going to work with polymorphism in the form of an Interface.
Interfaces are tool in C# and other object oriented programming languages that allow us to reduce the…
Yesterday we setup the players sword to use a collider that would animate with the sword to detect when the enemy is hit. We are going to expand on that a little bit today to get the players attack script started. This will be a pretty short article since we are just setting up the test that our sword is working and can hit things.
Before we start on the script we want to do some cleanup from yesterday and get things setup for the script.
//Time to add some substance to the game
So our mobile game is coming along quite nicely. The player can move and swing his weapon, jump and do all kinds of cool hero type stuff. The enemies can patrol there designated areas and look quite imposing. But you can probably tell from the image above its all surface right now. We can’t actually engage in combat with the big bad goals of cave doom. So our next goal is to get a combat system in place.
Our simple combat system is going to rely on a hitbox design. Using colliders…
Yesterday I discussed how we could use the concepts of inheritance and abstraction to create a base class that all of our enemies could use to prevent rewriting a ton of code or creating a mess in a single script.
Today, we will look at creating the child classes for the enemies so we can see what the inheritance looks like.
Yesterday we created the following base class for our enemies.
//Setting up the base class
Most aspiring developers get a little glassy-eyed when we discuss terms like Inheritance, encapsulation, abstraction and object-oriented programming. These concepts become a little more clear when we look at things in action, so let’s look at how this would work for creating enemies in a game.
First, let us discuss why we want to use these concepts. In a nutshell, programmers are lazy. We want to do things quickly, efficiently and with as little code as we can possibly get away with writing. …
Turning my passion for video games and 11 years of software development experience into a focus on video game development using Unity3D.