getting_started
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
getting_started [2023/01/28 15:13] – nkassai | getting_started [2023/02/21 09:00] (current) – nkassai | ||
---|---|---|---|
Line 3: | Line 3: | ||
**Author:** <Nathan Kassai> Email: < | **Author:** <Nathan Kassai> Email: < | ||
\\ | \\ | ||
- | **Date:** Last modified on <01/28/2023> | + | **Date:** Last modified on <01/29/2023> |
\\ | \\ | ||
**Keywords: | **Keywords: | ||
Line 16: | Line 16: | ||
* Understanding the layout and some key terminology | * Understanding the layout and some key terminology | ||
* Writing our first "Hello World" script | * Writing our first "Hello World" script | ||
+ | * Final Words | ||
+ | * Refresher Questions | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 28: | Line 30: | ||
==== Brief introduction to Unity ==== | ==== Brief introduction to Unity ==== | ||
- | On June 8th, 2005, the popular game engine we all know and love today, Unity, was released. Originally, Unity was solely designed to be just a game engine, a collection of tools, libraries, and assets to prototype a 2D/3D game. Why as a roboticist then would you benefit from learning Unity? | + | On June 8th, 2005, the popular game engine we all know and love today, Unity, was released. Originally, Unity was solely designed to be just a game engine; a collection of tools, libraries, and assets to prototype a 2D/3D game. Why as a roboticist then would you benefit from learning Unity? |
- | + | ||
- | (Maybe include video here of compilation of project used in the lab with Unity) | + | |
In this crash course, I plan on teaching you the basics of Unity: understanding how Unity works, learning how to write scripts to implement custom behaviors, general terminology, | In this crash course, I plan on teaching you the basics of Unity: understanding how Unity works, learning how to write scripts to implement custom behaviors, general terminology, | ||
Line 42: | Line 42: | ||
- | {{ : | + | {{ : |
After downloading, | After downloading, | ||
- | {{ : | + | {{ : |
- | Once you have reached this page, you may either | + | Once you have reached this page, you may either |
After logging in, it will ask if you would like to install the latest Unity editor. Press **Skip Installation** (we will be downloading an earlier Unity Editor version). Finally, Unity will ask you to activate a personal license, press **Agree and Get Personal Edition License**. | After logging in, it will ask if you would like to install the latest Unity editor. Press **Skip Installation** (we will be downloading an earlier Unity Editor version). Finally, Unity will ask you to activate a personal license, press **Agree and Get Personal Edition License**. | ||
Line 55: | Line 55: | ||
Once you have finalized the Unity Hub installation, | Once you have finalized the Unity Hub installation, | ||
- | {{ : | + | {{ : |
As previously mentioned, this is known as the **Unity Hub**. The Unity Hub is where you are able to manage all of your created projects, as well as install versions of the Unity Editor. The **Unity Editor** is where we actually create our applications. **We cannot create a project in Unity if we do not have a Unity Editor!**, so, lets us install a 2020+ version. | As previously mentioned, this is known as the **Unity Hub**. The Unity Hub is where you are able to manage all of your created projects, as well as install versions of the Unity Editor. The **Unity Editor** is where we actually create our applications. **We cannot create a project in Unity if we do not have a Unity Editor!**, so, lets us install a 2020+ version. | ||
Line 62: | Line 62: | ||
After pressing install, it gives you options to install additional packages. For now, we do not need any of these packages, we will just press install (this can take 10-20 minutes). | After pressing install, it gives you options to install additional packages. For now, we do not need any of these packages, we will just press install (this can take 10-20 minutes). | ||
- | {{ : | + | {{ : |
After the installation has completed, switch over to the Projects tab and press New Project. | After the installation has completed, switch over to the Projects tab and press New Project. | ||
- | {{ : | + | {{ : |
The template that we will be using for this project is **3D Core**! Press the core tab and press 3D Core as seen here. Once you select it, give your project a name, and choose where you would like this project to be stored. Once you have done that, press create project. | The template that we will be using for this project is **3D Core**! Press the core tab and press 3D Core as seen here. Once you select it, give your project a name, and choose where you would like this project to be stored. Once you have done that, press create project. | ||
- | {{ : | + | {{ : |
Once it has loaded, you should see this screen: | Once it has loaded, you should see this screen: | ||
- | {{ :unityscene.png? | + | {{ :unityscenebare.png? |
- | Now that Unity has been fully installed, | + | Now that Unity has been fully installed, |
===== Installing Visual Studio ===== | ===== Installing Visual Studio ===== | ||
Line 87: | Line 87: | ||
Once it gets to this page, scroll all the way down until you see **Game Development**, | Once it gets to this page, scroll all the way down until you see **Game Development**, | ||
- | (Add Image here) | ||
===== Understanding the Layout and Some Key Terminology ===== | ===== Understanding the Layout and Some Key Terminology ===== | ||
- | Congrats! You've loaded up into your first project. Now, before we do anything else, lets talk about what is currently on screen. | + | Congrats! You've loaded up into your first project. Now, before we do anything else, let' |
- | {{ : | + | {{ : |
- **Scene Window**: In this center rectangle, we have the Scene Window. This gives us a view as to what is located inside this current Unity Scene. For instance, as we add to this scene later on, you can visualize what you're adding through this window. If you wanted to see what the player sees, click on the tab right next to Scene. | - **Scene Window**: In this center rectangle, we have the Scene Window. This gives us a view as to what is located inside this current Unity Scene. For instance, as we add to this scene later on, you can visualize what you're adding through this window. If you wanted to see what the player sees, click on the tab right next to Scene. | ||
- | - **Hierarchy**: | + | - **Hierarchy**: |
- **Inspector**: | - **Inspector**: | ||
- **Project Management**: | - **Project Management**: | ||
Line 119: | Line 118: | ||
* A script which detects that the cube has collided with something | * A script which detects that the cube has collided with something | ||
- | The words **Script** and **Behavior** are synonymous with each other in Unity, however, the proper term for it is a **Component**. | + | The proper term for these special types of scripts are called |
- | A component is a script | + | A component is a script |
- | Lets try and get a cube to fall! To do this, we must first add the cube game object to the Hierarchy. To do so, bring your mouse to the Hierarchy, right click, hover over 3D object, and then select Cube. | + | Let' |
+ | {{ : | ||
- | (Add image) | + | Once the cube spawns in, click on it in the Hierarchy. As you can see in the inspector, there are different components that define what makes up this cube. |
+ | If you were to hit play now, nothing happens; the cube stays suspended in the air. | ||
+ | Well, let's fix that by adding a new component to our cube called, **Rigid Body**. This allows our game object to experience external forces | ||
- | As you can see in the inspector, there are different components which define what make up this cube. | + | {{ : |
- | Now, if you were to hit play now, nothing happens; the cube stays suspended in the air. | + | |
- | Well, lets fix that by adding a new component to our cube called, **Rigid Body**. This allows our game object to experience external forces (including gravity!). | + | Now, hit play again, and watch as the cube falls forever. |
Go ahead and spend some time playing with the other components and add other game objects to the scene! | Go ahead and spend some time playing with the other components and add other game objects to the scene! | ||
- | As I mentioned previously, | + | As I mentioned previously, Unity Devs added a large number |
Unity' | Unity' | ||
- | Before we do that, lets get Visual Studio connected with our Unity project! | + | Before we do that, let' |
- | To do so, go to the top left of Unity, select the Edit tab, and hit preferences. Next, hit the External Tools tab, scroll down to External Script Editor, hit the drop down, and select Visual Studio. | + | To do so, go to the top left of Unity, select the Edit tab, and hit preferences. |
- | Once that has updated, we are now ready to write our first script! | + | |
+ | {{ : | ||
+ | |||
+ | Next, hit the External Tools tab, scroll down to External Script Editor, hit the drop-down, and select Visual Studio. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Once that has been updated, we are now ready to write our first script! | ||
===== Writing Our First "Hello World" Script ===== | ===== Writing Our First "Hello World" Script ===== | ||
- | All we need to do to create our first script is to right click in our project management area, create, and then C# script. | + | All we need to do to create our first script is to right-click in our project management area, create, and then C# script. |
- | (image needed here) | + | {{ : |
For this script, call it **HelloPrint**. | For this script, call it **HelloPrint**. | ||
- | Next, double click the HelloPrint script and wait for it to load in Visual Studio. It should look like this after it has loaded: | + | Next, double-click the HelloPrint script and wait for it to load in Visual Studio. It should look like this after it has loaded: |
- | (image needed here) | + | {{ : |
At first, it can be pretty intimidating, | At first, it can be pretty intimidating, | ||
+ | - These lines allow us to call C# and Unity functions to implement in our code. | ||
+ | - This line defines a new Class called HelloPrint **Note: The name of this class MUST be the same as the file you created, if not, there will be errors when trying to apply this component to a game object.** Additionally, | ||
+ | - Start and Update are special types of functions. As seen by the comments, Start is a function that is called right before the first frame update. In other words, when you hit play, before the first frame is played, this function is called, and whatever code is inside it will run. However, this function is called once for every script that it is attached to. Update however is called once per frame. If your Unity scene is running at 60 FPS, this function and all code written inside it will be called 60 times per second. | ||
+ | |||
+ | Let's add a line of code to the start function so that once we hit play on the Unity scene, the phrase, "Hello World!", | ||
+ | |||
+ | To do so, type in the following line in between the curly braces as seen below: | ||
+ | |||
+ | Debug.Log(" | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Once you do this, hit Ctrl + s to save your script, and head back over to your Unity scene. | ||
+ | |||
+ | Now, if we hit play and switch over to the console tab, we can see that nothing printed out. Remember, this script is now a component; in order for the script to run, we must add it to a pre-existing game object. | ||
+ | |||
+ | Let's add this to our cube. Click on our Cube in the inspector, press Add Component, and type in the name of the script we just wrote **HelloPrint**, | ||
+ | |||
+ | Finally, switch over to the console tab and hit play. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | Congratulations! You have written your first Script in Unity! | ||
+ | |||
+ | ===== Final Words ===== | ||
+ | |||
+ | I hope you're excited about this course in Unity as you will learn a great deal about the plethora of features that this platform has to offer (both in game development and especially in robotics/ | ||
+ | |||
+ | |||
+ | ===== Refresher Questions ===== | ||
+ | At the end of each session, I like to ask questions to make sure you were able to understand all of the information provided. I'll either ask you to write a program that goes over what was taught in this session or simply ask true/false and or multiple-choice questions. **These are not homework assignments!** | ||
+ | - What is a Game Object? | ||
+ | - What is a Component? | ||
+ | - What is the difference between the Start and Update functions? | ||
+ | - What scripting language does Unity use? | ||
+ | - Write a script that will print " | ||
\\ | \\ |
getting_started.1674947631.txt.gz · Last modified: by nkassai