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.