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.
-
On the top-right menu, select the User icon > Sign in.
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.
-
Once you successfully logged in, select the Activate New License button on the top right.
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.
-
Once you see a license applied to your account, select the back arrow to leave the preferences menu.
Install the latest long-term support (LTS) version of Unity
-
On Unity Hub, select Installs on the left menu.
-
Select the Add button to add a new Unity installation.
The Add Unity Version dialog appears.
-
Choose the latest LTS version and select the Next button.
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.
-
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.
-
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.
-
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:
-
On Unity Hub, select Projects from the left menu.
-
Select the New button on the top-right corner.
The Create a new project with Unity dialog appears.
-
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.
A new project is created, and Unity opens when the project finishes loading.
-
On Unity Hub, select Projects from the left menu.
-
Select the New button on the top-right corner.
The Create a new project with Unity dialog appears.
- 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.
-
Select the Create button. A new project is created, and Unity opens when the project finishes loading.
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.
-
On the menu bar, select Edit > Preferences.
The Preferences dialog appears.
- Select the External Tools tab. From the External Script editor drop-down list, choose Visual Studio 2019.
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.
-
On the menu bar, select Unit > Preferences.
The Preferences dialog appears.
- Select the External Tools tab. From the External Script editor drop-down list, choose Visual Studio.
Create a cube
Now that Unity is configured, let's create a cube:
-
Right click on the Hierarchy window and choose 3D Object > Cube.
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:
Add a script
Let's create a script and add it to the cube.
-
Select the Cube object in the Hierarchy window.
You should see the Inspector window change to reflect the properties of the cube.
-
On the Inspector window, select the Add component button at the bottom.
A new drop-down list appears.
-
Enter the word new and choose New script.
-
Enter SpinCube as the name of the script and select the Create and Add button. This should add this new script to your cube.
-
You should also see the script appear in your Assets folder in the Project window on the bottom of the 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.
-
Visual Studio should look something like this, once it's fully loaded:
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:
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 theRotate
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.
-
Change the Y value to 1, and then press the Play button on the top of 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 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.
-
If the build process was a success, you should see the application running with the rotating cube. Press CMD+F to exit full screen.
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