How to Make a 3d Model in Unity

Introduction

Purpose

Set up your development environment and build your first real-time 3D app with Unity.

Prerequisites

None.

Time to Complete

10 minutes + 40 minutes of download/installation time

Scenario

A multi-platform game that shows a rotating 3D cube.

Download and install

Download and install Unity Hub:

Download Unity Hub

Unity Hub allows you to manage different Unity installations. After downloading it, follow the instructions on screen to set up Unity Hub on your machine.

Activate a new license

  • After the installation has finished, open Unity Hub if it's not already running.
  • If you're not on the License page automatically, select the Gear icon on the top-right menu and select License Management on the left menu.

    Unity Hub preferences

    Licenses management button

  • On the top-right menu, select the User icon > Sign in.

    Sign in menu

    The Unity Hub Sign In dialog appears.

  • Sign in to your Unity account or click on the create one link to create a new account. You can also use one of the social login options.

    sign-in options menu

  • Once you successfully logged in, select the Activate New License button on the top right.

    Licenses screen

    The New License Activation dialog appears.

  • Choose Unity Personal and then I don't use Unity in a professional capacity options. Press Done. Make sure you edit the license later if you start using Unity professionally to be compliant with the license agreement.

    Licenses choices screen

  • Once you see a license applied to your account, select the back arrow to leave the preferences menu.

    Leaving the preferences menu

Install the latest long-term support (LTS) version of Unity

  • On Unity Hub, select Installs on the left menu.

    Unity Hub Installs menu

  • Select the Add button to add a new Unity installation.

    Unity Hub Add installation button

    The Add Unity Version dialog appears.

  • Choose the latest LTS version and select the Next button.

    Latest Unity LTS version highlighted in the Unity Hub

    The LTS versions are the most stable, and they get updates and support for a longer time.

  • During the installation of Unity from the Unity Hub, choose to install the latest version of Visual Studio. If you already have a different edition of Visual Studio 2019 installed, you can uncheck this option. Select the Next button.

    Unity Hub Visual Studio install option

  • If you're installing Visual Studio with the Unity installation, the End User License Agreement appears. Read the terms and conditions and select I have read and agree with the above terms and conditions. Select the Done button. The installation begins. Installation can take some time depending on your machine.

Already have Visual Studio installed?

If you already had Visual Studio 2019 installed when setting up Unity Hub, you need the Unity workload installed.

To add the Unity workload to Visual Studio:

  • Press the Windows key, type Visual Studio Installer, and press Enter.
  • If prompted, allow the installer to update itself.
  • Find your Visual Studio 2019 installation and select More > Modify.
  • Select Game Development with Unity and then select the Modify button.

Visual Studio workloads dialog with the Game development with Unity workload selected

  • During the installation of Unity from the Unity Hub, choose to install the latest version of Visual Studio for Mac. If you don't have the option to install Visual Studio for Mac, you might already have a Visual Studio for Mac installation.

    Unity Hub Visual Studio for Mac install option

  • If you're installing Visual Studio with the Unity installation, the End User License Agreement appears. Read the terms and conditions and select I have read and agree with the above terms and conditions. Select the Done button. The installation begins. Installation can take some time depending on your machine.

While you wait for Unity to install

We highly recommend you watch this video to get a bit familiar with the Unity user interface while you wait for the installation to complete.

Create a Unity project

To begin, let's create a 3D Unity project:

  1. On Unity Hub, select Projects from the left menu.

  2. Select the New button on the top-right corner.

    Unity Hub New project button

    The Create a new project with Unity dialog appears.

  3. Select the 3D template and name the project 3DCube. If you'd like to change where the project will be saved, change the Location settings. Then, select the Create button.

    Unity Hub prompt to choose a project type and name

    A new project is created, and Unity opens when the project finishes loading.

  1. On Unity Hub, select Projects from the left menu.

  2. Select the New button on the top-right corner.

    Unity Hub New project button

    The Create a new project with Unity dialog appears.

  3. Select the 3D template and name the project 3DCube. Change the Location settings if you'd like to change where the project will be saved.
  4. Select the Create button. A new project is created, and Unity opens when the project finishes loading.

    Unity Hub prompt to choose a project type and name

Set the default code editor in Unity

Once Unity loads your project, things should work as intended, but let's check to see if Unity is using the correct installation of Visual Studio.

  1. On the menu bar, select Edit > Preferences.

    Unity's preferences under the Edit menu

    The Preferences dialog appears.

  2. Select the External Tools tab. From the External Script editor drop-down list, choose Visual Studio 2019.

    Unity's preferences dialog window with Visual Studio 2019 chosen as the external editor

    If you're not seeing Visual Studio 2019 on the list, select Browse on the drop-down list and locate your Visual Studio 2019 installation. The Visual Studio Community edition is typically found under %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\IDE or %ProgramFiles%\Microsoft Visual Studio\2019\Community\Common7\IDE.

  1. On the menu bar, select Unit > Preferences.

    Unity's preferences under the Unity menu

    The Preferences dialog appears.

  2. Select the External Tools tab. From the External Script editor drop-down list, choose Visual Studio.

    Unity's preferences dialog window with Visual Studio 2019 chosen as the external editor

Create a cube

Now that Unity is configured, let's create a cube:

  • Right click on the Hierarchy window and choose 3D Object > Cube.

    The Unity editor, with the 3D object and Cube menu options selected

    A cube object gets added to the Hierarchy window and the Scene view.

  • Select the Game tab and you should see a cube in the Game view, like the following:

    A cube floating in an empty space.

Add a script

Let's create a script and add it to the cube.

  1. Select the Cube object in the Hierarchy window.

    The Unity scene hierarchy with a cube game object chosen

    You should see the Inspector window change to reflect the properties of the cube.

  2. On the Inspector window, select the Add component button at the bottom.

    The inspector window when the cube is selected with the Add Component button highlighted

    A new drop-down list appears.

  3. Enter the word new and choose New script.

    A menu to create a new script in the Unity editor

  4. Enter SpinCube as the name of the script and select the Create and Add button. This should add this new script to your cube.

    A menu to add a script to a game object in the Unity editor

  5. You should also see the script appear in your Assets folder in the Project window on the bottom of the editor.

    A script added to the Project window in the unity editor

    You're now ready to edit that script and create some movements!

Edit a script

Let's make the cube spin now.

  • Double click on the SpinCube script in the Project window. This will automatically start Visual Studio. Doing that for the first time might take some time.

    The project window in Unity with the script highlighted

  • Visual Studio should look something like this, once it's fully loaded:

    The visual studio editor window, showing some auto-generated code

    You should see two methods on the generated C# code:

    • Start(): a method that runs once when the cube gets created in a 3D scene.
    • Update(): a method that runs once for every frame of the object that the 3D engine draws to the screen. This means it runs every time the engine wants to figure out where the cube should be in the scene.
  • Visual Studio should look something like this, once it's fully loaded:

    The Visual Studio for Mac editor window, showing some auto-generated code

    You should see two methods on the generated C# code:

    • Start(): a method that runs once when the cube gets created in a 3D scene.
    • Update(): a method that runs once for every frame of the object that the 3D engine draws to the screen. This means it runs every time the engine wants to figure out where the cube should be in the scene.

Let's start writing a script to rotate the cube by creating a variable that will control the rotation.

  • Insert the highlighted line of code above the Start method. This code creates a public Vector 3, with x,y,z coordinates that will control the rotations in a 3D space.

    C#

                                          public Vector3 RotateAmount;                    // Start is called before the first frame update                    void Start()                    {                                  
  • Then add the highlighted line of code inside the Update method. Every game object in Unity has a Transform script that dictates where it exists in 3D space and its rotation in 3D space. You'll use the Rotate method here and specify the rotation amount you want to happen on that game object.

    C#

                                          // Update is called once per frame                    void Update()                    {                                          transform.Rotate(RotateAmount);                    }                                  
  • Press CTRL + S to save your changes in Visual Studio.
  • Press CMD + S to save your changes in Visual Studio.
  • Now, go back to the Unity editor and choose the Cube object in the Hierarchy window again.

  • On the Inspector window, you should find that the Public variable you've created is now visible under the new script you added to the cube.

    The spinning cube component showing x,y,z editable values in the Unity Inspector window

  • Change the Y value to 1, and then press the Play button on the top of the Unity editor.

    The play button in the Unity editor

    Since the Update method runs every frame, you'll see that the cube will rotate by one for every frame. Feel free to change those values up and have some fun. You're now ready to build the game for different platforms.

Build the cube

Now, you're ready to export the game into an executable application.

  • On the Unity main menu, choose File > Build Settings.

  • Select the Add Open Scenes button to add the scene you just created.

  • By default, you'll see that the Platform is set to PC, Mac & Linux Standalone on the left. You can change the Target Platform further to choose the machine you're trying this tutorial on. When ready, select the Build and Run button. Save the executable application to your Desktop.

    The build dialog in the Unity editor

    The build dialog in the Unity editor

    The build process starts.

  • If the build process was a success, you should see the application running with the rotating cube. Press Alt+Enter to exit full screen.

    The build dialog in the Unity editor

  • If the build process was a success, you should see the application running with the rotating cube. Press CMD+F to exit full screen.

    The build dialog in the Unity editor

Next steps

Congratulations, you've built and run your first Unity application powered by .NET!

Keep learning

Now that you've got the basics, continue building your first game with Unity's self-guided tutorial:

The Official Guide to Your First Day in Unity

You might also be interested in...

How to Make a 3d Model in Unity

Source: https://dotnet.microsoft.com/learn/games/unity-tutorial/intro

0 Response to "How to Make a 3d Model in Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel