Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
In this video, we're gonna write our first line of code in Visual Studio. 2
2
That's going to be print Hello World, and then when we go into Unity and 3
3
click play, in the console area of Unity, it will print Hello World. 4
4
This is a small but very significant step in making sure that our environment is set 5
5
up correctly, and Unity and Visual Studio are working correctly together. 6
6
Let's start by talking briefly about how Unity and 7
7
Visual Studio relate to one another. 8
8
So Unity is our game engine. 9
9
This is where we say what the behaviors are in our game, and 10
10
how all the pieces relate to one another. 11
11
And how it all looks and how it all shapes up and comes together. 12
12
One of the pieces that we use in Unity is our code, 13
13
and our code is written in files that are .cs files. 14
14
These are also called scripts, and they're a bunch of texts that say what 15
15
are the rules and behaviors of the things that we want to have happen in our game. 16
16
And the place that we write these scripts is in Visual Studio. 17
17
Visual Studio is an IDE, that's an Integrated Developer Environment. 18
18
And it gives us a whole lot of structure and tools to make our life easier, and 19
19
to avoid making mistakes. 20
20
So if you're a Mac user, this is a good time to point out that there's really not 21
21
a lot of differences between Mac and PC when it comes to Unity and Visual Studio. 22
22
But in the next video, Ben is gonna through those differences, so 23
23
it's really clear what you're looking at and how it relates, and 24
24
how it differs from what we're seeing on the PC. 25
25
So let's go ahead and create our first scripts, and 26
26
use Visual Studio to make a little bit of magic in Unity. 27
27
So let's open up Unity Hub, few after you downloaded it, it might have a shortcut 28
28
on your desktop, or you might need to navigate to it through your Program menu. 29
29
When you open that up, you can see I've got a bunch of projects in here. 30
30
If this is the first time you are using Hub, then yours is probably empty. 31
31
And you wanna make sure that, 32
32
under Installs, you got 2018 or later ready to go. 33
33
So, from any of these tabs up hear, click on New. 34
34
And that will allow us to create a new project, 35
35
and it's gonna ask us where we want to save that. 36
36
Let me just show you my directory here. 37
37
I put that and then we can see exactly what's going on in here. 38
38
So for me, I've created under my D drive. 39
39
So just any of your drives. 40
40
I've got a D drive here, I've created a photo called Repos which is short for 41
41
the terminology repositories, which is something 42
42
that'll be relevant later on in the course when we look at source control. 43
43
And then within Repos, I've created Unity2D, 44
44
which is where all of the projects from this course are going to go, 45
45
and the first section we're working on isIntro_Setup. 46
46
So, I encourage you to do a similar structure, 47
47
have a Repos directory with our Unity2D course, 48
48
and then for this particular section it's intro and setup, ready and running this. 49
49
So when we go into start our new project, 50
50
we click on the three little dots to the right of location, down here, 51
51
and that will allow us to go and choose where we want to set that up. 52
52
Go to DATA, or DATA, depending from where you're from, Repos, and 53
53
then Unity2D, and then Intro_Setup. 54
54
So I'm gonna just click on that once and select Project, and 55
55
we'll use that as our project location. 56
56
Now it's really important to know that a Unity Project 57
57
is a folder with a set of directories and a set of files with inside it. 58
58
When we start a project, it's not just one file, it's a whole bunch of files. 59
59
We're gonna call the project name, here we'll call this Hello World, 60
60
as all good programming first steps should be a Hello World, and 61
61
under Template we're going to select 2D, and then click Create project. 62
62
There might be a little bit of loading, a little bit of setup, 63
63
a little bit of importing, particularly if it's the first time. 64
64
So bear with that, it should do all of that automatically, and 65
65
then we will be into the engine. 66
66
Okay, so that started up our project. 67
67
Let's just have a quick look in our directory to see what happened there 68
68
in the Intro_Setup. 69
69
We now have a Hello World folder, I've got a couple of other things in here that you 70
70
won't have yet, cuz I've put them in. 71
71
But the important thing is to see that we've got a Hello World. 72
72
Within that there's a whole bunch of folders that Unity's created for 73
73
us, including the Assets folder, and that's where all of our information, 74
74
all of our game assets, and artwork, and scripts. 75
75
Everything is gonna go into Assets, so that's being created for us. 76
76
If your layout looks different to mine, you can come up to the top right here, 77
77
it says Layout, click on that button and find Default. 78
78
When you click on Default, that should default everything back to the default 79
79
windows layout, so it should look the same as what I have here. 80
80
So from anywhere down in this Assets area down here, right click, go to Create, 81
81
and then find C# Script, click on that, and you'll see it create a script. 82
82
Now, important message, we wanna typing straight away the name of our script, 83
83
don't click anywhere else and don't hit Enter. 84
84
Cuz if you do that, you'll accidentally create this file with the default name. 85
85
And if we create it with the default name, 86
86
when we go and rename it in a moment, it will cause some issues and some errors. 87
87
So you wanna make sure that while the script name is still highlighted and blue, 88
88
that you start typing straight away. 89
89
We're gonna change the name of this to HelloWorld, no spaces. 90
90
And I've put capital H and capital W. 91
91
And you know you've created your script correctly if the name underneath 92
92
the script there matches the name we see over in inspector you can see public class 93
93
HelloWorld. 94
94
So if its Hello World there ,and HelloWorld under your script, success, 95
95
we are ready to go. 96
96
If they are different, Unity is gonna be a bit upset and 97
97
you need to delete your script and start that process again. 98
98
So let's double click on HelloWorld. 99
99
It'll open up Visual Studio. 100
100
There might be a little bit of initial setup and initial loading. 101
101
Okay, and there's a lot going on here. 102
102
There's a few things we don't need, so I'm gonna close over here, 103
103
my Solution Explorer, just x out on that. 104
104
And my Team Explorer and Properties, 105
105
all of those things we don't need at the moment, so I'm gonna close that out. 106
106
So this script that we created over here in Unity 107
107
already comes with a bunch of text, a bunch of information on it. 108
108
We're not gonna go into the details of that yet, 109
109
I promise you we'll get into all of that. 110
110
And in no time you'll understand everything that's going on within here. 111
111
But for now, we're just going to get our hands dirty by writing a line of code. 112
112
So, I want you to click on line number 9, clicking there underneath Start 113
113
verses void start, just follow along with me here, hands dirty, right. 114
114
Our first line of code and type print, and 115
115
after that we're gonna type open brackets or open parenthesis. 116
116
And then quotation mark, and you can see cuz we are in 117
117
our best friend of Visual Studio, it knows what we wanna do. 118
118
It's already give us a closed bracket and a closed quotation mark. 119
119
And it's already giving us some information down here saying, 120
120
hey you might wanna know this, and this might be useful. 121
121
This is great stuff. 122
122
Over time you'll recognize that, and you'll see this fantastic. 123
123
For now, don't worry about all that information coming out. 124
124
We're gonna finish typing here, we'll type Hello World. 125
125
And then down the end of our statement here, we need to type a ;, 126
126
and you can see when we did that the little squiggly red line went away. 127
127
I'll do that one more time. 128
128
When we've got no ; there's a squiggly red line seen, and 129
129
if you mouse over that, you can see ;expected. 130
130
So this is our best buddy Visual Studio trying to help us out here, 131
131
saying I really think you should put a semicolon there. 132
132
Yes, we do need to do one of those. 133
133
Okay then, I want to hit Save, and 134
134
you can see the little star that was up here went away. 135
135
And, we have a green line that appears to say that we have saved our script. 136
136
Now, back over into Unity this is a script we're working on. 137
137
It's been saved, now there's one last step we need to do. 138
138
Our script just sitting on it's own isn't doing anything, 139
139
we need to bring it into our world by attaching it to a game object. 140
140
And, the only game object we've got is our camera. 141
141
So, if your sample scene has closed, you can click the little arrow next to it. 142
142
That'll open it up to show all of the things in the hierarchy underneath 143
143
Sample Scene, and you can see we have main camera. 144
144
That's our game object, the only game object in the moment. 145
145
So we're going to drag our HelloWorld script on to our main camera at 146
146
the top here. 147
147
We could have also dragged it over here into the inspector while we're selected on 148
148
main camera, either these ways would have served the same purpose. 149
149
You can see now when clicked on main camera within the inspector, 150
150
we've got our HelloWorld script there. 151
151
If you come out to the top and click the Play button, and 152
152
open up the Console here, we haven't talked about the Console yet. 153
153
The Console is what allows us to see the messages, and 154
154
the information allows us to debug our game. 155
155
It's a great place to print things out. 156
156
You can see Hello World is written right in there. 157
157
Success, we have created our first line of code. 158
158
Now I have a challenge for you, and 159
159
what I would like you to do is to print Hello YourName. 160
160
So to modify our Hello World code, 161
161
instead of printing out Hello World, I'd like it to print out YourName. 162
162
And obviously it wouldn't say YourName, it would saying Hello Rick, or Hello Fred, or 163
163
Hello Bob, whatever your name might be. 164
164
So, pause the video now, go into the script, 165
165
change from Hello World to Hello YourName, Save, and 166
166
then go back into Unity and click Play, and see that it tops Hello YourName. 167
167
And after you do that, come back to the video and play the video again, and 168
168
I will my approach doing that as well, and we can finish off this excercise together. 169
169
So, I will see you in a moment. 170
170
Okay, welcome back. 171
171
We'll make sure we click out of play mode. 172
172
I'd left ourselves in play mode, and I really hope that you did that challenge. 173
173
I'm gonna ask you to do a challenge in each lecture in this course, and 174
174
it's super super important that you jump in and take on these challenges. 175
175
Okay, so I'm back over in VisualStudio here, and 176
176
you can see our statement print("Hello World"), I'm just gonna hop in here and 177
177
change this to "Hello Rick" and hit Save. 178
178
Back over into Unity, we don't need to attach it to the main camera again, 179
179
cuz it's already attached there. 180
180
If we click on the main camera, you can see Hello World, 181
181
it's been updated because we've saved it. 182
182
And then when I click play, you should see Hello Rick down here. 183
183
And this really was a quick exercise to make sure that our environment is 184
184
set up correctly. 185
185
In the next section of the course, Number Wizard, 186
186
we'll be looking at all the things that we went over very quickly here. 187
187
About the inspector, 188
188
about the layout, in terms of just things like semi-colons, why are we doing them? 189
189
So, all of that information we'll be covering in great detail 190
190
in the next section of the course. 191
191
During the next video Ben is going to be talking about Mac differences, 192
192
if you are a Mac person, that's a great video to watch. 193
193
If not, you can skip that video and go into the next video in the course. 194
194
Great work, and I will see you again soon.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.