Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
1
00:00:04,500 --> 00:00:08,127
In this video, we're gonna write our
first line of code in Visual Studio.
2
2
00:00:08,127 --> 00:00:12,824
That's going to be print Hello World,
and then when we go into Unity and
3
3
00:00:12,824 --> 00:00:17,459
click play, in the console area of Unity,
it will print Hello World.
4
4
00:00:17,459 --> 00:00:21,788
This is a small but very significant step
in making sure that our environment is set
5
5
00:00:21,788 --> 00:00:26,270
up correctly, and Unity and Visual Studio
are working correctly together.
6
6
00:00:26,270 --> 00:00:28,850
Let's start by talking
briefly about how Unity and
7
7
00:00:28,850 --> 00:00:30,880
Visual Studio relate to one another.
8
8
00:00:30,880 --> 00:00:32,800
So Unity is our game engine.
9
9
00:00:32,800 --> 00:00:36,450
This is where we say what
the behaviors are in our game, and
10
10
00:00:36,450 --> 00:00:38,620
how all the pieces relate to one another.
11
11
00:00:38,620 --> 00:00:41,430
And how it all looks and
how it all shapes up and comes together.
12
12
00:00:41,430 --> 00:00:45,060
One of the pieces that we
use in Unity is our code,
13
13
00:00:45,060 --> 00:00:49,350
and our code is written in
files that are .cs files.
14
14
00:00:49,350 --> 00:00:52,975
These are also called scripts, and
they're a bunch of texts that say what
15
15
00:00:52,975 --> 00:00:57,095
are the rules and behaviors of the things
that we want to have happen in our game.
16
16
00:00:57,095 --> 00:01:00,895
And the place that we write these
scripts is in Visual Studio.
17
17
00:01:00,895 --> 00:01:05,640
Visual Studio is an IDE, that's
an Integrated Developer Environment.
18
18
00:01:05,640 --> 00:01:10,560
And it gives us a whole lot of structure
and tools to make our life easier, and
19
19
00:01:10,560 --> 00:01:12,500
to avoid making mistakes.
20
20
00:01:12,500 --> 00:01:16,267
So if you're a Mac user, this is a good
time to point out that there's really not
21
21
00:01:16,267 --> 00:01:20,051
a lot of differences between Mac and PC
when it comes to Unity and Visual Studio.
22
22
00:01:20,051 --> 00:01:23,612
But in the next video,
Ben is gonna through those differences, so
23
23
00:01:23,612 --> 00:01:27,173
it's really clear what you're
looking at and how it relates, and
24
24
00:01:27,173 --> 00:01:29,799
how it differs from what
we're seeing on the PC.
25
25
00:01:29,799 --> 00:01:33,352
So let's go ahead and
create our first scripts, and
26
26
00:01:33,352 --> 00:01:37,500
use Visual Studio to make
a little bit of magic in Unity.
27
27
00:01:37,500 --> 00:01:41,620
So let's open up Unity Hub, few after you
downloaded it, it might have a shortcut
28
28
00:01:41,620 --> 00:01:45,870
on your desktop, or you might need to
navigate to it through your Program menu.
29
29
00:01:47,020 --> 00:01:49,940
When you open that up, you can see
I've got a bunch of projects in here.
30
30
00:01:49,940 --> 00:01:53,970
If this is the first time you are using
Hub, then yours is probably empty.
31
31
00:01:53,970 --> 00:01:55,430
And you wanna make sure that,
32
32
00:01:55,430 --> 00:01:59,930
under Installs, you got 2018 or
later ready to go.
33
33
00:01:59,930 --> 00:02:02,750
So, from any of these tabs up hear,
click on New.
34
34
00:02:02,750 --> 00:02:04,980
And that will allow us
to create a new project,
35
35
00:02:04,980 --> 00:02:07,290
and it's gonna ask us where
we want to save that.
36
36
00:02:07,290 --> 00:02:09,520
Let me just show you my directory here.
37
37
00:02:09,520 --> 00:02:12,180
I put that and then we can see
exactly what's going on in here.
38
38
00:02:12,180 --> 00:02:15,450
So for me, I've created under my D drive.
39
39
00:02:15,450 --> 00:02:16,840
So just any of your drives.
40
40
00:02:16,840 --> 00:02:21,000
I've got a D drive here, I've created
a photo called Repos which is short for
41
41
00:02:21,000 --> 00:02:23,550
the terminology repositories,
which is something
42
42
00:02:23,550 --> 00:02:28,080
that'll be relevant later on in the course
when we look at source control.
43
43
00:02:28,080 --> 00:02:31,740
And then within Repos,
I've created Unity2D,
44
44
00:02:31,740 --> 00:02:35,650
which is where all of the projects
from this course are going to go,
45
45
00:02:35,650 --> 00:02:38,170
and the first section we're
working on isIntro_Setup.
46
46
00:02:38,170 --> 00:02:40,870
So, I encourage you to
do a similar structure,
47
47
00:02:40,870 --> 00:02:43,705
have a Repos directory
with our Unity2D course,
48
48
00:02:43,705 --> 00:02:48,584
and then for this particular section it's
intro and setup, ready and running this.
49
49
00:02:48,584 --> 00:02:51,226
So when we go into start our new project,
50
50
00:02:51,226 --> 00:02:55,812
we click on the three little dots to
the right of location, down here,
51
51
00:02:55,812 --> 00:03:00,710
and that will allow us to go and
choose where we want to set that up.
52
52
00:03:00,710 --> 00:03:04,881
Go to DATA, or DATA, depending
from where you're from, Repos, and
53
53
00:03:04,881 --> 00:03:07,370
then Unity2D, and then Intro_Setup.
54
54
00:03:07,370 --> 00:03:11,348
So I'm gonna just click on that once and
select Project, and
55
55
00:03:11,348 --> 00:03:14,270
we'll use that as our project location.
56
56
00:03:14,270 --> 00:03:16,940
Now it's really important to
know that a Unity Project
57
57
00:03:16,940 --> 00:03:21,200
is a folder with a set of directories and
a set of files with inside it.
58
58
00:03:21,200 --> 00:03:26,090
When we start a project, it's not just
one file, it's a whole bunch of files.
59
59
00:03:26,090 --> 00:03:29,540
We're gonna call the project name,
here we'll call this Hello World,
60
60
00:03:29,540 --> 00:03:33,050
as all good programming first
steps should be a Hello World, and
61
61
00:03:33,050 --> 00:03:37,350
under Template we're going to select 2D,
and then click Create project.
62
62
00:03:40,796 --> 00:03:43,095
There might be a little bit of loading,
a little bit of setup,
63
63
00:03:43,095 --> 00:03:45,590
a little bit of importing,
particularly if it's the first time.
64
64
00:03:45,590 --> 00:03:48,450
So bear with that, it should do
all of that automatically, and
65
65
00:03:48,450 --> 00:03:50,890
then we will be into the engine.
66
66
00:03:50,890 --> 00:03:53,040
Okay, so that started up our project.
67
67
00:03:53,040 --> 00:03:56,220
Let's just have a quick look in our
directory to see what happened there
68
68
00:03:56,220 --> 00:03:57,530
in the Intro_Setup.
69
69
00:03:57,530 --> 00:04:01,420
We now have a Hello World folder, I've got
a couple of other things in here that you
70
70
00:04:01,420 --> 00:04:03,310
won't have yet, cuz I've put them in.
71
71
00:04:03,310 --> 00:04:05,890
But the important thing is to see
that we've got a Hello World.
72
72
00:04:05,890 --> 00:04:08,920
Within that there's a whole bunch
of folders that Unity's created for
73
73
00:04:08,920 --> 00:04:13,030
us, including the Assets folder, and
that's where all of our information,
74
74
00:04:13,030 --> 00:04:16,130
all of our game assets,
and artwork, and scripts.
75
75
00:04:16,130 --> 00:04:19,580
Everything is gonna go into Assets,
so that's being created for us.
76
76
00:04:19,580 --> 00:04:22,670
If your layout looks different to mine,
you can come up to the top right here,
77
77
00:04:22,670 --> 00:04:25,340
it says Layout,
click on that button and find Default.
78
78
00:04:25,340 --> 00:04:29,390
When you click on Default, that should
default everything back to the default
79
79
00:04:29,390 --> 00:04:32,520
windows layout, so it should look
the same as what I have here.
80
80
00:04:32,520 --> 00:04:38,160
So from anywhere down in this Assets area
down here, right click, go to Create,
81
81
00:04:38,160 --> 00:04:42,520
and then find C# Script, click on that,
and you'll see it create a script.
82
82
00:04:42,520 --> 00:04:46,680
Now, important message, we wanna typing
straight away the name of our script,
83
83
00:04:46,680 --> 00:04:48,850
don't click anywhere else and
don't hit Enter.
84
84
00:04:48,850 --> 00:04:53,510
Cuz if you do that, you'll accidentally
create this file with the default name.
85
85
00:04:53,510 --> 00:04:54,930
And if we create it with the default name,
86
86
00:04:54,930 --> 00:04:59,470
when we go and rename it in a moment,
it will cause some issues and some errors.
87
87
00:04:59,470 --> 00:05:04,300
So you wanna make sure that while the
script name is still highlighted and blue,
88
88
00:05:04,300 --> 00:05:06,620
that you start typing straight away.
89
89
00:05:06,620 --> 00:05:10,850
We're gonna change the name of
this to HelloWorld, no spaces.
90
90
00:05:10,850 --> 00:05:12,877
And I've put capital H and capital W.
91
91
00:05:12,877 --> 00:05:17,019
And you know you've created your script
correctly if the name underneath
92
92
00:05:17,019 --> 00:05:21,559
the script there matches the name we see
over in inspector you can see public class
93
93
00:05:21,559 --> 00:05:22,410
HelloWorld.
94
94
00:05:22,410 --> 00:05:25,750
So if its Hello World there ,and
HelloWorld under your script, success,
95
95
00:05:25,750 --> 00:05:26,740
we are ready to go.
96
96
00:05:26,740 --> 00:05:29,180
If they are different,
Unity is gonna be a bit upset and
97
97
00:05:29,180 --> 00:05:32,300
you need to delete your script and
start that process again.
98
98
00:05:32,300 --> 00:05:34,490
So let's double click on HelloWorld.
99
99
00:05:35,690 --> 00:05:36,920
It'll open up Visual Studio.
100
100
00:05:36,920 --> 00:05:40,120
There might be a little bit of
initial setup and initial loading.
101
101
00:05:40,120 --> 00:05:41,580
Okay, and there's a lot going on here.
102
102
00:05:41,580 --> 00:05:44,420
There's a few things we don't need,
so I'm gonna close over here,
103
103
00:05:44,420 --> 00:05:47,340
my Solution Explorer, just x out on that.
104
104
00:05:47,340 --> 00:05:49,510
And my Team Explorer and Properties,
105
105
00:05:49,510 --> 00:05:52,978
all of those things we don't need at
the moment, so I'm gonna close that out.
106
106
00:05:52,978 --> 00:05:55,550
So this script that we
created over here in Unity
107
107
00:05:55,550 --> 00:05:59,360
already comes with a bunch of text,
a bunch of information on it.
108
108
00:05:59,360 --> 00:06:01,010
We're not gonna go into
the details of that yet,
109
109
00:06:01,010 --> 00:06:03,050
I promise you we'll get into all of that.
110
110
00:06:03,050 --> 00:06:06,510
And in no time you'll understand
everything that's going on within here.
111
111
00:06:06,510 --> 00:06:11,352
But for now, we're just going to get our
hands dirty by writing a line of code.
112
112
00:06:11,352 --> 00:06:15,988
So, I want you to click on line number 9,
clicking there underneath Start
113
113
00:06:15,988 --> 00:06:20,639
verses void start, just follow along
with me here, hands dirty, right.
114
114
00:06:20,639 --> 00:06:23,637
Our first line of code and type print, and
115
115
00:06:23,637 --> 00:06:28,990
after that we're gonna type open
brackets or open parenthesis.
116
116
00:06:28,990 --> 00:06:32,910
And then quotation mark, and
you can see cuz we are in
117
117
00:06:32,910 --> 00:06:37,530
our best friend of Visual Studio,
it knows what we wanna do.
118
118
00:06:37,530 --> 00:06:41,450
It's already give us a closed bracket and
a closed quotation mark.
119
119
00:06:41,450 --> 00:06:43,730
And it's already giving us some
information down here saying,
120
120
00:06:43,730 --> 00:06:46,390
hey you might wanna know this,
and this might be useful.
121
121
00:06:46,390 --> 00:06:47,510
This is great stuff.
122
122
00:06:47,510 --> 00:06:50,590
Over time you'll recognize that,
and you'll see this fantastic.
123
123
00:06:50,590 --> 00:06:52,650
For now, don't worry about all
that information coming out.
124
124
00:06:52,650 --> 00:06:56,590
We're gonna finish typing here,
we'll type Hello World.
125
125
00:06:56,590 --> 00:07:01,311
And then down the end of our
statement here, we need to type a ;,
126
126
00:07:01,311 --> 00:07:05,060
and you can see when we did that
the little squiggly red line went away.
127
127
00:07:05,060 --> 00:07:06,890
I'll do that one more time.
128
128
00:07:06,890 --> 00:07:10,580
When we've got no ; there's
a squiggly red line seen, and
129
129
00:07:10,580 --> 00:07:14,560
if you mouse over that,
you can see ;expected.
130
130
00:07:14,560 --> 00:07:17,763
So this is our best buddy Visual Studio
trying to help us out here,
131
131
00:07:17,763 --> 00:07:20,511
saying I really think you
should put a semicolon there.
132
132
00:07:20,511 --> 00:07:21,447
Yes, we do need to do one of those.
133
133
00:07:21,447 --> 00:07:23,432
Okay then, I want to hit Save, and
134
134
00:07:23,432 --> 00:07:26,940
you can see the little star
that was up here went away.
135
135
00:07:26,940 --> 00:07:32,860
And, we have a green line that appears
to say that we have saved our script.
136
136
00:07:32,860 --> 00:07:35,840
Now, back over into Unity this
is a script we're working on.
137
137
00:07:35,840 --> 00:07:39,270
It's been saved,
now there's one last step we need to do.
138
138
00:07:39,270 --> 00:07:42,120
Our script just sitting on
it's own isn't doing anything,
139
139
00:07:42,120 --> 00:07:45,690
we need to bring it into our world
by attaching it to a game object.
140
140
00:07:45,690 --> 00:07:48,009
And, the only game object
we've got is our camera.
141
141
00:07:48,009 --> 00:07:53,280
So, if your sample scene has closed,
you can click the little arrow next to it.
142
142
00:07:53,280 --> 00:07:56,460
That'll open it up to show all of
the things in the hierarchy underneath
143
143
00:07:56,460 --> 00:08:00,555
Sample Scene, and
you can see we have main camera.
144
144
00:08:00,555 --> 00:08:03,742
That's our game object,
the only game object in the moment.
145
145
00:08:03,742 --> 00:08:08,251
So we're going to drag our HelloWorld
script on to our main camera at
146
146
00:08:08,251 --> 00:08:09,209
the top here.
147
147
00:08:09,209 --> 00:08:13,264
We could have also dragged it over here
into the inspector while we're selected on
148
148
00:08:13,264 --> 00:08:16,687
main camera, either these ways
would have served the same purpose.
149
149
00:08:16,687 --> 00:08:20,113
You can see now when clicked on
main camera within the inspector,
150
150
00:08:20,113 --> 00:08:22,310
we've got our HelloWorld script there.
151
151
00:08:22,310 --> 00:08:26,860
If you come out to the top and
click the Play button, and
152
152
00:08:26,860 --> 00:08:30,700
open up the Console here,
we haven't talked about the Console yet.
153
153
00:08:30,700 --> 00:08:35,020
The Console is what allows
us to see the messages, and
154
154
00:08:35,020 --> 00:08:37,740
the information allows
us to debug our game.
155
155
00:08:37,740 --> 00:08:39,580
It's a great place to print things out.
156
156
00:08:39,580 --> 00:08:42,580
You can see Hello World is
written right in there.
157
157
00:08:42,580 --> 00:08:46,270
Success, we have created
our first line of code.
158
158
00:08:46,270 --> 00:08:47,440
Now I have a challenge for you, and
159
159
00:08:47,440 --> 00:08:51,060
what I would like you to do
is to print Hello YourName.
160
160
00:08:51,060 --> 00:08:54,270
So to modify our Hello World code,
161
161
00:08:54,270 --> 00:08:58,070
instead of printing out Hello World,
I'd like it to print out YourName.
162
162
00:08:58,070 --> 00:09:02,024
And obviously it wouldn't say YourName, it
would saying Hello Rick, or Hello Fred, or
163
163
00:09:02,024 --> 00:09:03,885
Hello Bob, whatever your name might be.
164
164
00:09:03,885 --> 00:09:07,711
So, pause the video now,
go into the script,
165
165
00:09:07,711 --> 00:09:12,227
change from Hello World to Hello YourName,
Save, and
166
166
00:09:12,227 --> 00:09:18,538
then go back into Unity and click Play,
and see that it tops Hello YourName.
167
167
00:09:18,538 --> 00:09:23,290
And after you do that, come back to
the video and play the video again, and
168
168
00:09:23,290 --> 00:09:28,827
I will my approach doing that as well, and
we can finish off this excercise together.
169
169
00:09:28,827 --> 00:09:30,029
So, I will see you in a moment.
170
170
00:09:32,621 --> 00:09:33,880
Okay, welcome back.
171
171
00:09:33,880 --> 00:09:35,590
We'll make sure we click out of play mode.
172
172
00:09:35,590 --> 00:09:39,350
I'd left ourselves in play mode, and
I really hope that you did that challenge.
173
173
00:09:39,350 --> 00:09:43,307
I'm gonna ask you to do a challenge
in each lecture in this course, and
174
174
00:09:43,307 --> 00:09:47,990
it's super super important that you
jump in and take on these challenges.
175
175
00:09:47,990 --> 00:09:51,330
Okay, so
I'm back over in VisualStudio here, and
176
176
00:09:51,330 --> 00:09:54,320
you can see our statement print("Hello
World"), I'm just gonna hop in here and
177
177
00:09:54,320 --> 00:09:57,940
change this to "Hello Rick" and hit Save.
178
178
00:09:57,940 --> 00:10:01,790
Back over into Unity, we don't need to
attach it to the main camera again,
179
179
00:10:01,790 --> 00:10:02,950
cuz it's already attached there.
180
180
00:10:02,950 --> 00:10:05,498
If we click on the main camera,
you can see Hello World,
181
181
00:10:05,498 --> 00:10:07,573
it's been updated because we've saved it.
182
182
00:10:07,573 --> 00:10:12,719
And then when I click play,
you should see Hello Rick down here.
183
183
00:10:12,719 --> 00:10:16,574
And this really was a quick exercise
to make sure that our environment is
184
184
00:10:16,574 --> 00:10:17,830
set up correctly.
185
185
00:10:17,830 --> 00:10:19,680
In the next section of the course,
Number Wizard,
186
186
00:10:19,680 --> 00:10:22,650
we'll be looking at all the things
that we went over very quickly here.
187
187
00:10:22,650 --> 00:10:23,600
About the inspector,
188
188
00:10:23,600 --> 00:10:27,880
about the layout, in terms of just things
like semi-colons, why are we doing them?
189
189
00:10:27,880 --> 00:10:30,690
So, all of that information we'll
be covering in great detail
190
190
00:10:30,690 --> 00:10:32,240
in the next section of the course.
191
191
00:10:32,240 --> 00:10:35,048
During the next video Ben is going
to be talking about Mac differences,
192
192
00:10:35,048 --> 00:10:37,650
if you are a Mac person,
that's a great video to watch.
193
193
00:10:37,650 --> 00:10:40,670
If not, you can skip that video and
go into the next video in the course.
194
194
00:10:40,670 --> 00:10:42,150
Great work, and I will see you again soon.
20533
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.