What happens if the player is dead, what if your ammo has run out, what happens when we collect a powerup? All these scenarios can be set using “If statements”
If statements are used in a lot of programming languages and C# is no exception.
When programming there are a lot of cases where you want something to happen depending on what condition is met. It is a very powerful and straightforward tool in your programming arsenal but it can be confusing for someone new to programming.
So let's get to the bottom of these once and for all.
With the power to create you also get the responsibility of taking away, these are simple functions to use but can be difficult to master.
Let us take a moment to get acquainted with the use of these functions since we will be using them a lot while working in Unity.
When developing games you need a way to bring objects into existence. In Unity we use the Instantiate function to do just that.
When you are writing code it can sometimes be hard to translate the ideas you have in your head directly into code. Luckily there is a trick programmers use to make this a little easier that trick is Pseudo-code.
Pseudocode is the act of writing down functionality in plain English so it is easier to break it up into pieces of functionality and code. It is a very powerful tool in the arsenal of every programmer.
In the last series of articles, we created a Prototype of a simple shooter game where we used some of the most basic functionality to show what is possible and make you feel comfortable with the possibility you have with Unity.
Before we move on to Creating our first real game I want to take this opportunity to go a little deeper into some of the building blocks we have been using so far. Today we dive a little deeper into Variables.
Good day recruit today marks a new chapter in your training. You might know how to shoot but today you will learn to kill!
We covered the basic rules and behavior and taught you how to shoot, now let's introduce some live targes and get that killer instinct going!
Goodmorning recruit. I hope you had some time to rest, now let's get you squared away!
You have a weapon but that does not mean you are ready to use it. Until now there were no restrictions on how fast you can fire but that is over now we are going to introduce you to some trigger discipline.
Creating life comes with great responsibility, we have given our little square friend the power to move, run and even shoot.
Like raising a puppy it is not only about teaching them new tricks and behavior, even more important is to set boundaries! These powers can not just be used without limitation, there have to be some rules!
So what are these rules?
One of the most basic responses to danger is Fight or Flight. So let's work on this first.
We gave our little block the power to move all around its little environment! But before we unleash it into this scary new world we need to give it some basic response.
Last time we talked about the concept of movement. It made the game feel more alive but it feels like something is still missing… Its control! today we will dive deeper into how to achieve this using Unity.
So first off what is control? One definition is “determine the behavior or supervise the running of.” Simply put it is defining and setting the behavior you would want our objects to adhere to, this can include things like speed, direction, aggression boundaries and any other types of behavior you can think of depending on the object you are creating.
Movement is everywhere around us. Some things move with the wind, others with the waves and some things can even move themselves.
But how do you make things move within Unity you might ask? Simple! we use the transform component to move it around, now let's take a quick look at some ways we can achieve this.