Posted on

3D Character Selection Menu

Unity Tutorial for Beginners

In this Unity tutorial for beginners, I will teach you how to create a very cool 3D character selection menu. This menu system uses 3D models of the character to display what the players are selecting. This tutorial for beginners will teach you about all different UI components and the code behind it.

Working in Unity

To begin we will start in Unity. You will need to have the 3D models that you want to be selectable. You need to have these 3D models in line with each other and make sure they are evenly spaced from one another. We will then create a World Space Canvas, scale it down and position and rotate so that it is floating above or in front of the 3D models. We will then create what is called a scrollrect or a scroll view. This is an image object the allows you to slide the UI objects that are children to the Scroll View. For the content of the Scrollrect we will have a UI image that overlaps the 3D models. We will then create UI buttons, one for each Character, and place the buttons over top of each 3D model. The last thing that we need to do is make our character models children to our content object.

Coding a Selection Menu

Now that we have Unity all set up for this tutorial we will talk about the code. We will need two scripts for this Game mechanic. The first will be called the StoreController and the other will be call StoreButton. In the store controller script, we will create code that will lerp our content object to a new position vector3 variable. In the StoreButton script, we will create two functions one that will set an int variable that we can then later use to instantiate the right character model for our player in the multiplayer scene. The second function will be for measuring the distance between the button selected and the center of our scrollrect. We will then use this distance to set the new position variable of our StoreController script.

More Unity

Once back in Unity we will need to apply these scripts. The StoreController script can be attached to our scroll view object and our StoreButton script can be attached to each of the buttons. We then need to set our variable and apply the functions of our StoreButton scripts to the On Click events of our UI buttons.

Test the Game

Finally, we can test our game. You should be able to scroll all your character to the left and right and you should be able to click on each character which will center them in our scene.

Posted on

Top-Down Shooter Video Game Tutorial – Player Movement

For this tutorial, we will be teaching you how to make a player movement controller for a top-down shooter video game. We will be working with Unity 2018 to create this movement controller. This controller is what we are using for our Season 001 project which will be a top-down space shooter.

After teaching how to make this controller for a single-player game. We will then teach you how to make it into a controller that will work across a multiplayer network that will work in a multiplayer game.

Posted on

Unity Health Bar Tutorial – Using Fill Images

How to make a health bar

Welcome to this quick game mechanic tutorial on how to make a health bar using fill images in Unity 3D. In this lesson, we will teach you how to create and update fill meters that you can use for health bars, shield bars, stamina bars, or even experience bars.

Create a Health Bar Object in Unity

To create a fill bar all you have to do is Is create a UI image object. you then you need to set the rect transform so the health bar is positioned and sized the way you want. You then need to apply a source image to the image component so that the Image type drop-down menu becomes available. You then can set the image type to Filled which will make it so you can determine the fill amount of our health bar. You can then decide if you want your fill meter to be a linear or a radial health bar by setting the fill mode. With your health bars created we will now switch over to the code we need.

Update Health Bar with C# Code

To get your health bar to update you will need at least three variables. Two of them need to be int or float. One will be for your current health. The other will be for the max health and the last one will be for holding the image component of the. To then update the health bar you only need one line of code. You will first need to access the fill amount of the image variable and set it equal to the current health divided by the max health. This will give you a decimal value of a percentage of how much health you currently have over how much total health you could have. You will need to have this line of code right after any time you change your current health value.

Test your Work

Inside Unity, you need to make sure you set all the variables and then you can test your game. If you follow along with this video you should then have a working health bar.