Create GUI Menu with 3D Objects – Unity3D (C#)
There are 2 ways to create a menu for your game: Unity’s GUI elements or custom objects. We will create a menu with custom 3D objects in this tutorial.
This type of menu acts like game scene. So, we need a menu scene to place our menu. The basic idea is to show, hide or animate the objects when you click them. Remember that disadvantages of this menu are to create different scripts for each button and the high memory space. Create a 3D project and start to create your buttons.
You can create a world for this scene or you can use just a solid color. I created a street for the background of my menu buttons.
Now, create 2 buttons from cube tool. Add textures as New Game and Quit.
Create a script and attach it to New Game button. We will use OnMouseUP() function and call anything with it. For New Game button, lets call the game scene.
When you click on New Game Button, Level 1 scene (you can edit levels in build menu) will be loaded. If you want to show something such as credits in this scene, you need to hide these buttons and show the credits image or object. You can use the code below to hide or show objects.
public GameObject quitButton;
public GameObject playButton;
public GameObject creditsButton;
public GameObject credits;
public GameObject backButton;
Create a credits button and attach this code. When you click on credits button, all buttons will be hidden and credits will be shown. The back button will be shown too. After that, you can create a code for back button, hide credits and show main menu buttons. You hide objects with objectName.SetActive(false) and show objects with objectName.SetActive(true). Don’t forget to assign public game objects.
©Coffee Break Codes – Create GUI Menu with 3D Objects – Unity3D (C#)