WEBVTT 1 00:00:05.712 --> 00:00:09.854 Game Advanced Prototype 3 2 00:00:09.854 --> 00:00:12.111 GCC Academy 3 00:00:27.346 --> 00:00:28.495 Hello 4 00:00:28.495 --> 00:00:32.006 I am Youngho Lee, and I am in charge of the shooting game production course 5 00:00:32.006 --> 00:00:36.458 In this unit, we will learn about prototype 3 6 00:00:36.458 --> 00:00:39.576 The learning content is about making bullet movement 7 00:00:39.576 --> 00:00:41.149 making bullet firing 8 00:00:41.149 --> 00:00:43.302 and making enemy movement 9 00:00:43.688 --> 00:00:47.578 Making Bullet Movement 10 00:00:48.373 --> 00:00:51.650 Let's create a bullet movement 11 00:00:51.650 --> 00:00:54.636 First, let's create bullets 12 00:00:54.636 --> 00:00:58.042 and then implement the shape of the bullets flying 13 00:00:58.042 --> 00:00:59.891 Let's go to Unity 14 00:00:59.891 --> 00:01:02.000 and create a bullet game object first 15 00:01:02.000 --> 00:01:04.574 In the hierarchy, press + 16 00:01:04.574 --> 00:01:08.000 and click Cube in 3D Object 17 00:01:08.000 --> 00:01:10.782 Let's put Bullet in the name 18 00:01:10.782 --> 00:01:13.178 Let's put Bullet 19 00:01:13.178 --> 00:01:15.802 and press Reset in Transform for the position 20 00:01:19.000 --> 00:01:20.000 It's here 21 00:01:20.000 --> 00:01:23.000 and I'll make the size smaller 22 00:01:23.000 --> 00:01:24.941 than the player 23 00:01:27.366 --> 00:01:28.812 I'll put it like this 24 00:01:31.337 --> 00:01:34.198 And since this bullet actually needs to move 25 00:01:34.198 --> 00:01:36.238 so, let's create a script 26 00:01:37.574 --> 00:01:41.267 In the Project window, in the Scripts folder 27 00:01:41.267 --> 00:01:44.000 press + and put C# Script 28 00:01:44.000 --> 00:01:46.618 Let's put Bullet in the name 29 00:01:50.924 --> 00:01:53.485 Once the Bullet script is created 30 00:01:53.485 --> 00:01:55.851 drag and drop it onto the Bullet game object 31 00:01:55.851 --> 00:01:56.782 like this 32 00:01:59.000 --> 00:02:03.881 Now, let's define 33 00:02:03.881 --> 00:02:06.169 this bullet's roles in the script 34 00:02:08.327 --> 00:02:10.653 What does this bullet want to do? 35 00:02:10.653 --> 00:02:16.099 It's going to keep moving upward 36 00:02:16.099 --> 00:02:18.000 That's what the bullet does 37 00:02:18.000 --> 00:02:20.000 So, this bullet 38 00:02:20.000 --> 00:02:22.000 This bullet class itself 39 00:02:22.000 --> 00:02:24.119 is made up of properties or functions 40 00:02:24.119 --> 00:02:26.584 What properties are needed 41 00:02:26.584 --> 00:02:30.000 to perform this sentence? 42 00:02:30.000 --> 00:02:32.050 In the end, you'll need to keep 43 00:02:32.050 --> 00:02:33.604 asking the planner 44 00:02:33.604 --> 00:02:37.188 What information is needed when you try to implement this 45 00:02:37.188 --> 00:02:38.733 in this sentence? 46 00:02:38.733 --> 00:02:42.812 That's what you can talk about with the necessary properties 47 00:02:42.812 --> 00:02:47.643 At this point, you might need the movement speed 48 00:02:47.643 --> 00:02:49.000 You need to tell us the movement speed 49 00:02:49.000 --> 00:02:52.406 so that we can move according to the planner's intention 50 00:02:52.406 --> 00:02:55.832 And we've set the movement speed 51 00:02:55.832 --> 00:02:57.732 but it would be good if the planner 52 00:02:57.732 --> 00:02:59.545 could directly modify this part 53 00:03:02.000 --> 00:03:04.000 Okay, so for the movement speed 54 00:03:04.000 --> 00:03:10.475 let's put public float speed here 55 00:03:10.475 --> 00:03:12.653 and set it to 10 56 00:03:12.653 --> 00:03:15.624 The player moved at a speed of 5, right? 57 00:03:15.624 --> 00:03:17.515 If you go to PlayerMove 58 00:03:17.515 --> 00:03:19.792 you can see it's moving at a speed 5 59 00:03:19.792 --> 00:03:21.392 But what about Bullet? 60 00:03:21.392 --> 00:03:23.188 I'll process it to move at 10 61 00:03:25.713 --> 00:03:31.643 And since this guy wants to keep moving upward 62 00:03:31.643 --> 00:03:34.703 we need to 63 00:03:34.703 --> 00:03:36.604 implement this in either 64 00:03:36.604 --> 00:03:39.832 Start or Update 65 00:03:39.832 --> 00:03:41.703 Since this content needs to keep moving 66 00:03:41.703 --> 00:03:43.377 we'll need to put it in Update 67 00:03:47.485 --> 00:03:51.000 Then, let's break this sentence down 68 00:03:51.000 --> 00:03:52.604 into a little more detail 69 00:03:52.604 --> 00:03:56.129 What is this sentence ultimately trying to do? 70 00:03:56.129 --> 00:04:00.198 It wants to move 71 00:04:00.198 --> 00:04:02.337 To move, you need something 72 00:04:02.337 --> 00:04:06.594 That is, you need a direction 73 00:04:06.594 --> 00:04:08.000 In other words, you need to find a direction 74 00:04:08.000 --> 00:04:10.000 to move in that direction 75 00:04:10.000 --> 00:04:11.445 If you look at the priorities 76 00:04:11.445 --> 00:04:15.198 this is how the priorities should be 77 00:04:15.198 --> 00:04:19.049 Find the direction first, and then move in that direction 78 00:04:19.049 --> 00:04:20.970 Here, what can we see 79 00:04:20.970 --> 00:04:22.059 as the direction? 80 00:04:22.059 --> 00:04:25.604 Let's put direction in Vector3 81 00:04:25.604 --> 00:04:27.366 dir 82 00:04:27.366 --> 00:04:31.802 This would be Up in Vector3 83 00:04:36.000 --> 00:04:42.653 The movement formula is P=P0+vt 84 00:04:42.653 --> 00:04:43.742 It's like this 85 00:04:43.742 --> 00:04:47.356 So let's put it in like this 86 00:04:47.356 --> 00:04:52.000 As we did before, what happens to P0? 87 00:04:52.000 --> 00:04:59.723 The position of the transform is P0 88 00:04:59.723 --> 00:05:05.643 Next, vt is dir times 89 00:05:05.643 --> 00:05:08.766 the size and we'll put in Speed 90 00:05:08.766 --> 00:05:11.554 which is the property 91 00:05:11.554 --> 00:05:14.604 Then, if you do * Time.deltaTime 92 00:05:14.604 --> 00:05:17.000 you'll get vt, right? 93 00:05:17.000 --> 00:05:23.317 And if you put this value of P=P0+vt in Vector3 94 00:05:23.317 --> 00:05:28.416 and finally put it in the position of the transform 95 00:05:28.416 --> 00:05:31.000 the content will be complete 96 00:05:31.000 --> 00:05:34.346 You can break it down like this and write it 97 00:05:34.346 --> 00:05:40.039 but if you write it as one sentence, it's like this: P0 98 00:05:40.039 --> 00:05:46.000 Then + vt, you can write it like this 99 00:05:46.000 --> 00:05:50.208 If you combine these sentences into one, it'll be the same 100 00:05:50.208 --> 00:05:56.000 This much will be P0 and vt 101 00:05:56.000 --> 00:05:59.980 So you can see that this sentence and this sentence are the same 102 00:06:02.000 --> 00:06:05.455 Let's save it and check it 103 00:06:05.455 --> 00:06:09.000 Bullet already has a Bullet (Script) attached to it 104 00:06:09.000 --> 00:06:12.600 When you press the play button 105 00:06:12.600 --> 00:06:15.693 this Bullet will fly up 106 00:06:15.693 --> 00:06:19.000 Here, there is something we need to differentiate 107 00:06:19.000 --> 00:06:22.465 Speed ​​is currently exposed in Bullet 108 00:06:22.465 --> 00:06:25.733 Player doesn't 109 00:06:25.733 --> 00:06:29.733 In other words, if the planner wants to modify 110 00:06:29.733 --> 00:06:31.841 these values continuously 111 00:06:31.841 --> 00:06:36.267 Player has to ask the programmer 112 00:06:36.267 --> 00:06:39.515 to modify this number 113 00:06:39.515 --> 00:06:40.828 Then, the Player has to keep 114 00:06:40.828 --> 00:06:43.000 modifying this number while working 115 00:06:43.000 --> 00:06:46.000 This is a very bad way 116 00:06:46.000 --> 00:06:49.650 It would be better to allow the planner 117 00:06:49.650 --> 00:06:52.346 to modify his components 118 00:06:52.346 --> 00:07:01.148 So, I think it would be good to make this number 119 00:07:01.148 --> 00:07:03.000 5 like Bullet in Player 120 00:07:03.000 --> 00:07:07.800 and use this speed value like this 121 00:07:07.800 --> 00:07:09.861 How did I do that? 122 00:07:09.861 --> 00:07:13.261 I added a property called 123 00:07:13.261 --> 00:07:15.000 public float speed to PlayerMove 124 00:07:15.000 --> 00:07:17.350 I processed this property value speed variable 125 00:07:17.350 --> 00:07:21.000 to be used in vt 126 00:07:21.000 --> 00:07:25.554 Then, when we save and go 127 00:07:25.554 --> 00:07:30.723 Player's speed 5 is exposed like this 128 00:07:30.723 --> 00:07:34.000 So we can change this value 129 00:07:34.000 --> 00:07:38.455 This way, the planner can modify it easily 130 00:07:38.455 --> 00:07:42.129 I showed you how to do this 131 00:07:42.129 --> 00:07:44.851 without asking the programmer 132 00:07:44.851 --> 00:07:47.267 Bullet is also exposed like this 133 00:07:47.267 --> 00:07:51.673 So when you play, the bullet goes up 134 00:07:51.673 --> 00:07:54.208 the Player moves according to the speed 135 00:07:54.208 --> 00:07:56.000 and this part becomes the motion 136 00:07:56.525 --> 00:08:00.356 Making a Bullet Launcher 137 00:08:00.792 --> 00:08:04.475 This time, let's try firing a bullet 138 00:08:04.475 --> 00:08:07.247 If you pull the trigger 139 00:08:07.247 --> 00:08:11.733 these processes will occur 140 00:08:11.733 --> 00:08:16.624 If you look at it, you will pull the trigger like this 141 00:08:16.624 --> 00:08:20.000 Then, there are two ways 142 00:08:20.000 --> 00:08:22.450 As seen on this screen, first 143 00:08:22.450 --> 00:08:25.000 I'll call the bullet factory 144 00:08:25.000 --> 00:08:27.000 You will place an order at the factory 145 00:08:27.000 --> 00:08:29.300 So you will receive the bullet 146 00:08:29.300 --> 00:08:32.000 and fire it 147 00:08:32.000 --> 00:08:36.030 The second is that the bullet will come out like this 148 00:08:36.030 --> 00:08:41.000 but even if you look at this bullet, there are a lot of bullets in the magazine 149 00:08:41.000 --> 00:08:43.247 So, the structure is to 150 00:08:43.247 --> 00:08:45.835 take bullets from the magazine and fire them bang bang bang 151 00:08:45.835 --> 00:08:49.436 every time you pull the trigger 152 00:08:49.436 --> 00:08:56.386 The second is to fire bullets from the magazine 153 00:08:56.386 --> 00:09:01.317 Of course, we will fire bullets from the magazine 154 00:09:01.317 --> 00:09:04.267 but the bullets in the magazine 155 00:09:04.267 --> 00:09:07.782 have to be produced from the bullet factory here 156 00:09:07.782 --> 00:09:10.832 In actual practice, this structure 157 00:09:10.832 --> 00:09:14.000 is used in which the factory directly produces bullets 158 00:09:14.000 --> 00:09:18.000 Here, practice is what we are talking about in the game 159 00:09:18.000 --> 00:09:21.614 Here, we will look at some information related to the factory 160 00:09:21.614 --> 00:09:24.402 Later on, we will try putting bullets 161 00:09:24.402 --> 00:09:26.911 in the magazine 162 00:09:26.911 --> 00:09:29.611 It's a little ignorant, but we're going to do this 163 00:09:29.611 --> 00:09:31.109 every time we pull the trigger 164 00:09:31.109 --> 00:09:35.436 When we pull the trigger, we will call the bullet factory 165 00:09:35.436 --> 00:09:40.186 At this time, this factory is smoking 166 00:09:40.186 --> 00:09:46.138 but stopped, and at this time 167 00:09:46.138 --> 00:09:49.505 Mr. Kim is sleeping on a cot 168 00:09:49.505 --> 00:09:51.000 Mr. Kim is sleeping here 169 00:09:51.000 --> 00:09:53.654 Ring ring ring 170 00:09:53.654 --> 00:09:57.267 Then Mr. Kim has to jump out of his sleep 171 00:09:57.267 --> 00:10:03.000 So he says, "Hello!" and answers the phone 172 00:10:03.000 --> 00:10:06.000 Then I say urgently 173 00:10:06.000 --> 00:10:08.158 I'll call him Mr. Kim 174 00:10:08.158 --> 00:10:10.608 Hey, Mr. Kim, I just pulled the trigger 175 00:10:10.608 --> 00:10:13.673 so make me a bullet quickly 176 00:10:13.673 --> 00:10:16.173 Then Mr. Kim says, "Okay, I understand," 177 00:10:16.173 --> 00:10:23.000 and immediately lowers the lever and starts the factory 178 00:10:23.000 --> 00:10:25.850 Then, since the factory isn't running 179 00:10:25.850 --> 00:10:30.346 the conveyor belt has to move first 180 00:10:30.346 --> 00:10:33.416 If there's a container for materials 181 00:10:33.416 --> 00:10:35.916 he puts lead and gunpowder in it 182 00:10:35.916 --> 00:10:38.000 and Mr. Kim works hard 183 00:10:38.000 --> 00:10:41.950 Then how? He cuts the lead 184 00:10:41.950 --> 00:10:46.416 makes all the gunpowder, and a bullet comes out 185 00:10:46.416 --> 00:10:48.564 A bullet like this comes out 186 00:10:48.564 --> 00:10:50.327 So, how do we do this bullet? 187 00:10:50.327 --> 00:10:54.366 Here, let's load bullets onto the truck 188 00:10:54.366 --> 00:10:57.000 Like this, we load bullets onto the truck 189 00:10:57.000 --> 00:11:03.604 Then he'll come along this road in the truck 190 00:11:03.604 --> 00:11:05.436 Then he'll give me a bullet 191 00:11:05.436 --> 00:11:09.000 Then I'll shoot the bullet here, bang! 192 00:11:09.000 --> 00:11:12.000 It'll fly 193 00:11:12.000 --> 00:11:16.000 But I'm not going to shoot just once like this, and shoot three times 194 00:11:16.000 --> 00:11:18.000 Then what will happen? 195 00:11:18.000 --> 00:11:21.594 I'll have to make a phone call and wake up Mr. Kim 196 00:11:21.594 --> 00:11:24.844 If I asked Mr. Kim to make a bullet and shoot three times 197 00:11:24.844 --> 00:11:27.653 I'll have to say Mr. Kim three times 198 00:11:27.653 --> 00:11:29.303 Then, every time, Kim gets up 199 00:11:29.303 --> 00:11:32.198 lowers the lever, starts the factory 200 00:11:32.198 --> 00:11:34.614 puts in the lead, adds gunpowder, shaves it 201 00:11:34.614 --> 00:11:37.000 makes a bullet, gets on the truck, and delivers it to me 202 00:11:37.000 --> 00:11:39.000 And whenever I call Mr. Kim 203 00:11:39.000 --> 00:11:41.752 he'll have to keep repeating this process 204 00:11:41.772 --> 00:11:45.336 What if you were to 205 00:11:45.336 --> 00:11:48.247 burst and shoot in a way that 206 00:11:48.247 --> 00:11:53.327 we usually call a machine gun? 207 00:11:53.327 --> 00:11:55.317 It'll be like Mr. Kiiiiiim 208 00:11:55.317 --> 00:11:58.317 Then, Mr. Kim would continue 209 00:11:58.317 --> 00:12:01.495 to do this at high speed 210 00:12:01.495 --> 00:12:04.762 This would be very inefficient 211 00:12:04.762 --> 00:12:06.129 It would be inefficient 212 00:12:06.129 --> 00:12:12.643 If you were to make one bullet in this process 213 00:12:12.643 --> 00:12:15.752 this would inevitably happen 214 00:12:15.752 --> 00:12:17.752 If you were to improve this process 215 00:12:17.752 --> 00:12:19.485 what part would you improve 216 00:12:19.485 --> 00:12:23.396 to continuously shoot bullets quickly? 217 00:12:23.396 --> 00:12:26.396 Some might think 218 00:12:26.396 --> 00:12:29.196 Oh, we should improve the roads a bit 219 00:12:29.196 --> 00:12:30.119 You might think that way 220 00:12:30.119 --> 00:12:33.772 Then delivery would be faster, so that would be okay 221 00:12:33.772 --> 00:12:36.822 But you could also think this way 222 00:12:36.822 --> 00:12:38.445 This is a bullet factory 223 00:12:38.445 --> 00:12:41.267 Since it only produces one bullet, isn't that a waste? 224 00:12:41.267 --> 00:12:44.967 And if this factory stops and starts 225 00:12:44.967 --> 00:12:48.624 It would be overloaded 226 00:12:48.624 --> 00:12:51.158 So if you just turn on the factory 227 00:12:51.158 --> 00:12:54.653 and make a thousand bullets at once 228 00:12:54.653 --> 00:12:57.000 the factory would be really fast when making those things 229 00:12:57.000 --> 00:12:59.000 What if you make them? 230 00:12:59.000 --> 00:13:02.564 Then, you can just load them up and run 231 00:13:02.564 --> 00:13:06.406 Then, I can receive it without having to order from the factory anymore 232 00:13:06.406 --> 00:13:08.495 and shoot as many bullets as I want 233 00:13:08.495 --> 00:13:15.000 In other words, I can request this part all at once 234 00:13:15.000 --> 00:13:17.000 We call this batching 235 00:13:17.000 --> 00:13:20.000 We call it batch processing 236 00:13:20.000 --> 00:13:25.000 In reality, this process also happens, Batch 237 00:13:25.000 --> 00:13:27.000 Of course, this is the case in reality 238 00:13:27.000 --> 00:13:29.218 and this same process occurs on the computer side 239 00:13:29.218 --> 00:13:31.436 when doing some processing 240 00:13:31.436 --> 00:13:33.564 If we organize the terms 241 00:13:33.564 --> 00:13:40.653 this factory, in our computer software 242 00:13:40.653 --> 00:13:42.763 we can call it a file in computer science 243 00:13:45.495 --> 00:13:49.614 And the bullet created from this factory file 244 00:13:49.614 --> 00:13:53.178 is called an instance 245 00:13:53.178 --> 00:13:54.634 The bullet is created like this, right? 246 00:13:54.634 --> 00:13:57.337 I have to get an instance like this 247 00:13:57.337 --> 00:13:59.000 There is something that gets it like this 248 00:13:59.000 --> 00:14:03.713 This passage is called a Stream 249 00:14:03.713 --> 00:14:07.000 It is Stream, a 250 00:14:07.000 --> 00:14:09.247 It is called a stream 251 00:14:09.247 --> 00:14:12.005 Then, when I read the file 252 00:14:12.005 --> 00:14:13.168 and receive the instance through the Stream 253 00:14:13.168 --> 00:14:16.000 I only send the bullet 254 00:14:16.000 --> 00:14:19.000 What if we navigated to an image 255 00:14:19.000 --> 00:14:21.000 and double-click to open it? 256 00:14:21.000 --> 00:14:24.000 You double-click the file 257 00:14:24.000 --> 00:14:25.703 and ask it to open it 258 00:14:25.703 --> 00:14:26.802 That's a double-click 259 00:14:26.802 --> 00:14:31.352 When the file is opened 260 00:14:31.352 --> 00:14:33.406 memory data comes in through a stream 261 00:14:33.406 --> 00:14:37.505 To display it on the screen, we need an instance 262 00:14:37.505 --> 00:14:41.000 We take it and print pixels on the screen 263 00:14:41.000 --> 00:14:43.000 That's how it appears on the screen 264 00:14:43.000 --> 00:14:48.000 You can think of this bullet as the image you see on the screen 265 00:14:48.000 --> 00:14:50.000 This is a series of processes 266 00:14:50.000 --> 00:14:54.228 and the process of opening this file is ultimately slow 267 00:14:54.228 --> 00:14:55.654 When you open the file 268 00:14:55.654 --> 00:14:58.000 you can create 269 00:14:58.000 --> 00:15:00.000 many of them at once 270 00:15:00.000 --> 00:15:02.000 That's called batching 271 00:15:02.000 --> 00:15:06.356 Or, what can we say on our side? 272 00:15:06.356 --> 00:15:10.436 What's your labor pool? 273 00:15:10.436 --> 00:15:12.186 If you have some leftovers, can you give me some? Can you lend me some? 274 00:15:12.186 --> 00:15:13.099 They can say like this 275 00:15:13.099 --> 00:15:15.000 That's called a labor pool 276 00:15:15.000 --> 00:15:17.000 That's when we use the term pool 277 00:15:17.000 --> 00:15:19.455 In this case, bullets, game objects 278 00:15:19.455 --> 00:15:21.955 creating these objects 279 00:15:21.955 --> 00:15:24.119 so that there are extra ones is called a Pool 280 00:15:24.119 --> 00:15:26.495 and we add an Object in front of it 281 00:15:26.495 --> 00:15:31.000 That's called Object Pool 282 00:15:31.000 --> 00:15:33.198 In other words, to improve this speed 283 00:15:33.198 --> 00:15:35.048 the task of creating multiple bullets 284 00:15:35.048 --> 00:15:37.000 and multiple objects in advance 285 00:15:37.000 --> 00:15:39.386 is called an object pool 286 00:15:39.386 --> 00:15:43.663 Opening this file is the same structure as a network server 287 00:15:43.673 --> 00:15:47.713 that is, when you access various websites such as Naver, Kakao 288 00:15:47.713 --> 00:15:49.742 or Google 289 00:15:49.742 --> 00:15:51.426 When you access a portal site 290 00:15:51.426 --> 00:15:53.554 When you connect 291 00:15:53.554 --> 00:15:56.604 to connect to their network 292 00:15:56.604 --> 00:15:58.911 this Connection happens 293 00:15:58.911 --> 00:16:01.000 The users make the connection 294 00:16:01.000 --> 00:16:02.109 This is the same 295 00:16:02.109 --> 00:16:05.792 I am a user who hits the website 296 00:16:05.792 --> 00:16:08.317 Then, a connection is made here 297 00:16:08.317 --> 00:16:11.594 This is the same as opening a file and doing this work 298 00:16:11.594 --> 00:16:14.109 When you send and receive data 299 00:16:14.109 --> 00:16:18.198 and this work continues every time you access it 300 00:16:18.198 --> 00:16:20.445 it will be slow 301 00:16:20.445 --> 00:16:24.376 If there are 1 million users, it will be very slow 302 00:16:24.376 --> 00:16:25.950 If there are 10 million users 303 00:16:25.950 --> 00:16:28.188 the server may even go down 304 00:16:28.188 --> 00:16:31.544 Since it is slow at this time 305 00:16:31.544 --> 00:16:33.832 opening a file is a very slow task 306 00:16:33.832 --> 00:16:37.327 Opening a network connection is a slow task 307 00:16:37.327 --> 00:16:40.000 So it would be good to have a connection pool 308 00:16:40.000 --> 00:16:43.000 That is why it is called a connection pool 309 00:16:43.000 --> 00:16:46.703 There are a series of computer science terms like this 310 00:16:46.703 --> 00:16:49.158 So when we fire our bullets 311 00:16:49.158 --> 00:16:51.108 we will first make them directly 312 00:16:51.108 --> 00:16:53.703 in the factory in the prototype 313 00:16:53.703 --> 00:16:56.327 Later, in the beta version, we will use the object pool 314 00:16:56.327 --> 00:16:59.127 to improve the speed in advance 315 00:16:59.127 --> 00:17:00.525 and work for it 316 00:17:00.525 --> 00:17:03.275 First, let's try making these bullets 317 00:17:03.275 --> 00:17:05.445 in the factory 318 00:17:05.445 --> 00:17:09.000 In Visual Studio, there is a Bullet section, right? 319 00:17:09.000 --> 00:17:11.218 This is a bullet that has already been made 320 00:17:11.218 --> 00:17:15.000 So, we need to fire that bullet 321 00:17:15.000 --> 00:17:18.000 So the firing will be done by the Player 322 00:17:18.000 --> 00:17:20.416 Since the Player pulls the trigger 323 00:17:20.416 --> 00:17:23.772 there is a script for moving the Player 324 00:17:23.772 --> 00:17:26.703 so now let's create a script for firing and paste it 325 00:17:28.465 --> 00:17:31.416 In the Project window, click +, and in C# 326 00:17:31.416 --> 00:17:35.327 this time, let's enter PlayerFire 327 00:17:39.000 --> 00:17:40.762 PlayerFire will be created like this 328 00:17:40.762 --> 00:17:43.436 If we drag and drop this onto 329 00:17:43.436 --> 00:17:45.136 our Player game object like this 330 00:17:45.136 --> 00:17:48.673 the PlayerFire script will be created 331 00:17:48.673 --> 00:17:50.485 Let's double-click and open it 332 00:17:55.594 --> 00:17:58.445 This is what PlayerFire does 333 00:17:58.445 --> 00:18:05.366 We want to create a bullet when the user presses the fire button 334 00:18:05.366 --> 00:18:07.337 We'll do this 335 00:18:07.337 --> 00:18:12.000 So, what properties are needed here? 336 00:18:12.000 --> 00:18:14.604 The planner needs to tell you 337 00:18:14.604 --> 00:18:17.742 There can be multiple bullet factories 338 00:18:17.742 --> 00:18:20.317 When making bullets, you said that they are made at bullet factories 339 00:18:20.317 --> 00:18:22.792 Then, when there are multiple bullet factories 340 00:18:22.792 --> 00:18:25.000 we need the address of the bullet factory 341 00:18:25.000 --> 00:18:27.426 to know which bullet factory to make them at 342 00:18:27.426 --> 00:18:30.228 So we need a bullet factory here 343 00:18:32.465 --> 00:18:37.792 And once the bullets are made 344 00:18:37.792 --> 00:18:40.208 where will they be placed and fired? 345 00:18:40.208 --> 00:18:43.000 You can't fire the bullets from your hand 346 00:18:43.000 --> 00:18:46.000 You need to decide whether to fire them from the wing or the muzzle 347 00:18:46.000 --> 00:18:47.000 You might need this 348 00:18:47.000 --> 00:18:51.000 So you might need a muzzle 349 00:18:51.000 --> 00:18:53.650 Let's add these two 350 00:18:53.650 --> 00:18:56.149 as required properties of the class 351 00:18:58.109 --> 00:19:00.614 First, let's make a bullet factory 352 00:19:00.614 --> 00:19:06.218 If you look at the bullet factory 353 00:19:06.218 --> 00:19:09.139 you can see a bullet already made here 354 00:19:09.139 --> 00:19:12.495 How do you make a bullet factory 355 00:19:12.495 --> 00:19:15.366 to make this bullet? You can make it like this 356 00:19:15.366 --> 00:19:19.000 If you look, I'll make another folder in Assets 357 00:19:19.000 --> 00:19:21.000 Press + and select Folder 358 00:19:21.000 --> 00:19:26.535 I'll put it under Prefabs 359 00:19:26.535 --> 00:19:29.000 I'll make a folder called Prefabs here 360 00:19:29.000 --> 00:19:31.673 This bullet factory 361 00:19:31.673 --> 00:19:34.495 is called a file on our side 362 00:19:34.495 --> 00:19:38.000 I want this bullet to become a file 363 00:19:38.000 --> 00:19:41.000 Then, we can open this file every time 364 00:19:41.000 --> 00:19:43.455 and create an instance of this bullet 365 00:19:43.455 --> 00:19:45.465 So, what does it look like conceptually? 366 00:19:45.465 --> 00:19:50.000 This thing in the Hierarchy is called an instance 367 00:19:50.000 --> 00:19:52.650 Everything that goes up in the Hierarchy scene 368 00:19:52.650 --> 00:19:53.802 is called an instance 369 00:19:53.802 --> 00:19:55.238 It's an instance 370 00:19:55.238 --> 00:19:58.317 It's already been created and is in memory 371 00:19:58.317 --> 00:20:00.167 However, it hasn't been 372 00:20:00.167 --> 00:20:02.119 saved to the hard disk yet 373 00:20:02.119 --> 00:20:05.168 The space where it's saved to the hard disk is this project window 374 00:20:05.168 --> 00:20:09.267 In other words, we call things saved to the hard disk files 375 00:20:09.267 --> 00:20:13.643 So, if I want this instance here to be a file 376 00:20:13.643 --> 00:20:15.891 where should it be? 377 00:20:15.891 --> 00:20:19.594 If it's in the project window, it'll be a file 378 00:20:19.594 --> 00:20:22.525 Conceptually, this is how Unity 379 00:20:22.525 --> 00:20:25.416 uses this UX 380 00:20:25.416 --> 00:20:28.436 If you grab a Bullet and drag and drop it 381 00:20:28.436 --> 00:20:30.772 into the Prefabs folder 382 00:20:30.772 --> 00:20:35.752 a bullet Prefabs named Bullet will be created 383 00:20:35.752 --> 00:20:36.970 This is a file 384 00:20:36.970 --> 00:20:38.720 In Unity, we call these 385 00:20:38.720 --> 00:20:41.039 Prefabs 386 00:20:41.039 --> 00:20:43.239 Game objects that have become files 387 00:20:43.239 --> 00:20:46.198 What do you call these? 388 00:20:46.198 --> 00:20:48.792 Prefabs 389 00:20:48.792 --> 00:20:51.901 So what about the color of this bullet? 390 00:20:51.901 --> 00:20:55.198 It's blue 391 00:20:55.198 --> 00:20:56.832 It turned into blue 392 00:20:56.832 --> 00:20:59.931 Since this bullet was created here 393 00:20:59.931 --> 00:21:03.574 I'm going to make it so that it's only created 394 00:21:03.574 --> 00:21:05.000 when the user presses the fire button 395 00:21:05.000 --> 00:21:07.000 You can delete this one 396 00:21:07.000 --> 00:21:09.386 Why? Because it's already a file 397 00:21:09.386 --> 00:21:11.386 What? If you want to use it again? 398 00:21:11.386 --> 00:21:13.465 You can drag and drop it 399 00:21:13.465 --> 00:21:18.198 here or there 400 00:21:18.198 --> 00:21:21.257 You can create as many bullets as you want 401 00:21:21.257 --> 00:21:24.475 as instances 402 00:21:24.475 --> 00:21:27.257 If you have a file, you can open it 403 00:21:27.257 --> 00:21:30.327 to continue creating bullets here 404 00:21:30.327 --> 00:21:32.416 But when do you create this? 405 00:21:32.416 --> 00:21:34.475 When the user presses the fire button 406 00:21:34.475 --> 00:21:38.000 This becomes a bullet factory 407 00:21:38.000 --> 00:21:39.525 What is this? 408 00:21:39.525 --> 00:21:42.683 The game object has become a file 409 00:21:42.683 --> 00:21:43.871 It has become an asset 410 00:21:43.871 --> 00:21:47.148 So, we can declare the bullet factory like this 411 00:21:47.148 --> 00:21:54.009 How about putting it as a property 412 00:21:54.009 --> 00:21:55.346 public GameObject bulletFactory? 413 00:21:55.346 --> 00:21:58.564 It's for receiving the bullet factory, it's a variable 414 00:21:58.564 --> 00:22:00.000 Why is it a game object? 415 00:22:00.000 --> 00:22:03.208 Bullet factory, what was the prefab we were making in the first place? 416 00:22:03.208 --> 00:22:06.000 It was a game object 417 00:22:06.000 --> 00:22:08.450 If you look at Player 418 00:22:08.450 --> 00:22:11.000 Bullet Factory appears in Player Fire 419 00:22:11.000 --> 00:22:12.750 and you can drag and drop this Bullet 420 00:22:12.750 --> 00:22:15.000 into it like this 421 00:22:15.000 --> 00:22:18.000 That means the bullet factory is connected 422 00:22:18.000 --> 00:22:20.832 You have to pay attention to the name 423 00:22:20.832 --> 00:22:22.228 This isn't a bullet, what is it? 424 00:22:22.228 --> 00:22:24.614 It's a bullet factory 425 00:22:24.614 --> 00:22:29.000 Next, how do we make the muzzle? 426 00:22:29.000 --> 00:22:34.396 Let's put public GameObject 427 00:22:34.396 --> 00:22:37.376 firePosition here 428 00:22:37.376 --> 00:22:40.000 Then, we created the muzzle 429 00:22:40.000 --> 00:22:42.554 We don't have a muzzle yet 430 00:22:42.554 --> 00:22:46.495 Right, let's make a muzzle 431 00:22:46.495 --> 00:22:49.237 Let's see, I think the muzzle 432 00:22:49.237 --> 00:22:52.733 should be around this position on this Player 433 00:22:52.733 --> 00:22:54.583 If it has wings later 434 00:22:54.583 --> 00:22:57.663 I want it to shoot two shots 435 00:22:57.663 --> 00:23:00.752 Then I can put it here, right? 436 00:23:00.752 --> 00:23:03.663 So that the bullet comes out here 437 00:23:03.663 --> 00:23:05.063 Since it doesn't have that right now 438 00:23:05.063 --> 00:23:06.841 let's process it 439 00:23:06.841 --> 00:23:09.485 so the bullet comes out around this part 440 00:23:09.485 --> 00:23:12.129 So, if you select Player 441 00:23:12.129 --> 00:23:16.069 press + here and Create Empty 442 00:23:16.069 --> 00:23:19.643 It will go up to this level in the same Hierarchy structure 443 00:23:19.643 --> 00:23:21.119 We can drag and drop it 444 00:23:21.119 --> 00:23:24.515 to Player like this, but this method also exists 445 00:23:24.515 --> 00:23:27.089 If you right-click on Player 446 00:23:27.089 --> 00:23:30.139 you can see Create Empty 447 00:23:30.139 --> 00:23:32.178 or 3D Object here 448 00:23:32.178 --> 00:23:34.822 Let's click Create Empty here 449 00:23:34.822 --> 00:23:39.267 Then, it will be registered as a Player child 450 00:23:39.267 --> 00:23:42.208 The location will be registered at 0, 0 451 00:23:42.208 --> 00:23:46.049 Let's name it FirePosition 452 00:23:46.049 --> 00:23:47.396 For the muzzle 453 00:23:49.921 --> 00:23:52.445 Why did I set it to Empty? 454 00:23:52.445 --> 00:23:55.346 It doesn't need to be visible, so I made it like this 455 00:23:55.346 --> 00:23:59.356 Since it doesn't need to be visible, only the Transform is there 456 00:23:59.356 --> 00:24:05.515 It only has this that can adjust the location, rotation angle, and size 457 00:24:05.515 --> 00:24:09.346 I'll grab this FirePosition 458 00:24:09.346 --> 00:24:11.366 and put it here like this 459 00:24:11.366 --> 00:24:15.693 Then, the bullet will come out from this part 460 00:24:15.693 --> 00:24:18.238 So, if you select Player again 461 00:24:18.238 --> 00:24:21.000 you can see that I put FirePosition here 462 00:24:21.000 --> 00:24:23.400 Let's drag and drop 463 00:24:23.400 --> 00:24:26.307 FirePosition here 464 00:24:26.307 --> 00:24:29.634 Then, FirePosition is assigned 465 00:24:29.634 --> 00:24:32.742 What if there is no public? 466 00:24:32.742 --> 00:24:36.277 If there is no public 467 00:24:36.277 --> 00:24:41.733 if you go and look, FirePosition is gone 468 00:24:41.733 --> 00:24:42.633 Why is that? 469 00:24:42.633 --> 00:24:45.792 Only this public can be exposed to the outside 470 00:24:45.792 --> 00:24:48.802 So you have to attach it like this, public 471 00:24:48.802 --> 00:24:51.123 If you don't use anything 472 00:24:51.123 --> 00:24:55.257 the default access modifier is Private 473 00:24:55.257 --> 00:25:00.931 So I exposed bulletFactory and firePosition 474 00:25:00.931 --> 00:25:05.331 Now, let's implement this part 475 00:25:05.331 --> 00:25:07.681 to create bullets 476 00:25:07.681 --> 00:25:09.440 when the user presses the fire button 477 00:25:09.440 --> 00:25:13.140 These sentences must be placed in a function 478 00:25:13.140 --> 00:25:15.553 The functions we know are either Start or Update 479 00:25:15.553 --> 00:25:17.400 There is only one of these two 480 00:25:17.400 --> 00:25:20.050 Even if you create your own function 481 00:25:20.050 --> 00:25:21.400 you must put 482 00:25:21.400 --> 00:25:23.400 Start or Update in the function call 483 00:25:23.400 --> 00:25:26.450 So where should that sentence be implemented? 484 00:25:26.450 --> 00:25:29.050 If the call is made directly from Update 485 00:25:29.050 --> 00:25:34.200 to Start, it will be a bullet once when it is born 486 00:25:34.200 --> 00:25:37.200 And it may not even be possible to press the fire button 487 00:25:37.200 --> 00:25:40.500 So, let's put it in Update 488 00:25:40.500 --> 00:25:42.600 so that it can continuously create bullets 489 00:25:42.600 --> 00:25:45.919 whenever the user presses the fire button during its life 490 00:25:45.919 --> 00:25:48.219 To do this, the ultimate goal 491 00:25:48.219 --> 00:25:53.080 is to fire bullets, right? 492 00:25:53.080 --> 00:25:57.080 It's to create bullets, right? 493 00:25:57.080 --> 00:26:00.520 So, what do you need to fire bullets? 494 00:26:00.520 --> 00:26:04.703 You need bullets 495 00:26:04.703 --> 00:26:07.803 You need bullets to fire bullets 496 00:26:07.803 --> 00:26:10.839 And here's the question 497 00:26:10.839 --> 00:26:14.991 Why do you suddenly create bullets? According to this sentence 498 00:26:14.991 --> 00:26:21.519 since the user presses the fire button 499 00:26:21.519 --> 00:26:24.819 there are three things 500 00:26:24.819 --> 00:26:27.769 the user presses the fire button, a bullet is created 501 00:26:27.769 --> 00:26:29.911 and the bullet is fired 502 00:26:29.911 --> 00:26:32.960 Strictly speaking, firing a bullet 503 00:26:32.960 --> 00:26:34.610 means that when we create a bullet, we've already 504 00:26:34.610 --> 00:26:36.240 set it to go up 505 00:26:36.240 --> 00:26:38.800 We just need to decide where the bullet will come out 506 00:26:38.800 --> 00:26:45.560 So, if we set the location like this 507 00:26:45.560 --> 00:26:47.520 If you make a bullet and set the location 508 00:26:47.520 --> 00:26:50.120 the bullet will come out from that location 509 00:26:50.120 --> 00:26:53.080 So, if we look at it in order, the most important flow is that 510 00:26:53.080 --> 00:26:56.280 the user presses the fire button 511 00:26:56.280 --> 00:27:00.680 to create a bullet and set the location 512 00:27:00.680 --> 00:27:02.759 of the bullet 513 00:27:02.759 --> 00:27:06.360 So, if the user presses the fire button 514 00:27:06.360 --> 00:27:08.959 we can see this if the user 515 00:27:08.959 --> 00:27:10.320 presses the fire button 516 00:27:10.320 --> 00:27:14.870 The grammar used in the C# language then 517 00:27:14.870 --> 00:27:17.560 is called if 518 00:27:17.560 --> 00:27:20.520 If the user's input is processed 519 00:27:20.520 --> 00:27:23.439 we said that the Input class processes it 520 00:27:23.439 --> 00:27:26.641 Now, if we do ., among the properties or functions 521 00:27:26.641 --> 00:27:28.966 we'll use the function 522 00:27:28.966 --> 00:27:32.891 function GetButtonDown 523 00:27:32.891 --> 00:27:34.599 It means button is pressed 524 00:27:34.599 --> 00:27:35.959 Then there's also something that was pressed and then released, right? 525 00:27:35.959 --> 00:27:38.665 Then there's ButtonUp 526 00:27:38.665 --> 00:27:42.639 If you look here, Down means it was pressed, and Up means it was released 527 00:27:42.639 --> 00:27:44.289 Then what's being kept pressed? 528 00:27:44.289 --> 00:27:46.720 It's doing GetButton 529 00:27:46.720 --> 00:27:49.470 This uses GetButton when it is 530 00:27:49.470 --> 00:27:51.120 being kept pressed 531 00:27:51.120 --> 00:27:53.639 Since we will use the exact moment of pressing 532 00:27:53.639 --> 00:27:56.559 we'll use GetButtonDown 533 00:27:56.559 --> 00:28:00.239 Here, Fire1 means clicking the left mouse button 534 00:28:00.239 --> 00:28:04.680 or the left Ctrl button 535 00:28:04.680 --> 00:28:09.380 At this time, you can process the following contents 536 00:28:09.380 --> 00:28:12.599 to be implemented 537 00:28:12.599 --> 00:28:16.149 Fire1 is the Input Manager 538 00:28:16.149 --> 00:28:17.680 in Project Settings 539 00:28:17.680 --> 00:28:20.959 of the Edit menu of Unity 540 00:28:20.959 --> 00:28:23.400 There is an Input Manager in Project Settings 541 00:28:23.400 --> 00:28:26.464 Fire1 is set like this 542 00:28:29.959 --> 00:28:33.559 So first, if the user presses the fire button 543 00:28:33.559 --> 00:28:34.639 this part will be it 544 00:28:34.639 --> 00:28:37.720 If this is true, the button was pressed 545 00:28:37.720 --> 00:28:40.679 so that you can create a bullet 546 00:28:40.679 --> 00:28:43.759 How do you create a bullet in Unity? 547 00:28:43.759 --> 00:28:46.809 Instantiate, Mr. Kim, create a bullet 548 00:28:46.809 --> 00:28:48.839 in the bullet factory 549 00:28:48.839 --> 00:28:51.320 and give it to me 550 00:28:51.320 --> 00:28:55.000 It is called a factory method called Instantiate 551 00:28:55.000 --> 00:28:55.950 Factory function 552 00:28:55.950 --> 00:29:00.759 It automatically creates everything in this 553 00:29:00.759 --> 00:29:02.440 Giving it to me 554 00:29:02.440 --> 00:29:05.440 means creating a bullet in the bullet factory 555 00:29:05.440 --> 00:29:08.399 Instantiate, you can put a bullet factory here 556 00:29:08.399 --> 00:29:12.759 bulletFactory, if you put a bullet factory in 557 00:29:12.759 --> 00:29:15.240 it will create a bullet 558 00:29:15.240 --> 00:29:16.520 and it is just like a game object, right? 559 00:29:16.520 --> 00:29:19.199 If you put any of these game objects in 560 00:29:19.199 --> 00:29:22.158 It will clone it and create it 561 00:29:24.039 --> 00:29:25.440 This is just a function 562 00:29:25.440 --> 00:29:27.279 If you made one for me like this 563 00:29:27.279 --> 00:29:29.720 I could store it in a variable and use it 564 00:29:29.720 --> 00:29:32.080 when I set the position and do things like that 565 00:29:32.080 --> 00:29:38.119 I could do this GameObject bullet 566 00:29:38.119 --> 00:29:41.000 This here is a bullet factory 567 00:29:41.000 --> 00:29:42.119 and what is this? 568 00:29:42.119 --> 00:29:47.399 This is a file, and this is called an instance 569 00:29:47.399 --> 00:29:50.000 Since the instance from here is stored here 570 00:29:50.000 --> 00:29:52.000 you can think of this as an instance 571 00:29:52.000 --> 00:29:54.100 How do you set 572 00:29:54.100 --> 00:29:56.679 the position of the bullet itself? 573 00:29:56.679 --> 00:30:01.079 If you say bullet., you can draw a circle 574 00:30:01.079 --> 00:30:02.520 among your properties or functions 575 00:30:02.520 --> 00:30:04.520 Who has the position here? 576 00:30:04.520 --> 00:30:06.919 Transform has it, in the game object 577 00:30:06.919 --> 00:30:10.320 And if you say transform., what is the position 578 00:30:10.320 --> 00:30:13.639 among the properties or functions? Position 579 00:30:13.639 --> 00:30:16.199 Where are we going to set the position of this bullet? 580 00:30:16.199 --> 00:30:18.600 This part of the muzzle that we put here 581 00:30:18.600 --> 00:30:21.720 is this muzzle firePosition 582 00:30:21.720 --> 00:30:26.775 If you put this transform.position 583 00:30:26.775 --> 00:30:31.902 it will be assigned to the muzzle position 584 00:30:31.902 --> 00:30:36.119 Okay? Let's save it 585 00:30:36.119 --> 00:30:38.883 and go and press the play button 586 00:30:44.091 --> 00:30:47.160 Then, bang bang bang bang, the bullet will come out 587 00:30:47.160 --> 00:30:49.359 It will come out even if you move and shoot 588 00:30:49.359 --> 00:30:52.241 What do you think? You can see that it comes out from that location 589 00:30:52.241 --> 00:30:54.000 depending on the position of the muzzle 590 00:30:54.000 --> 00:30:55.559 Should I put it here? 591 00:30:55.559 --> 00:30:58.279 Bang bang bang bang, it will come out from that location 592 00:30:58.279 --> 00:31:00.359 Strangely enough, I'll turn off the play button 593 00:31:00.359 --> 00:31:02.799 So, the position of this muzzle is here, but where does it go? 594 00:31:02.799 --> 00:31:05.399 If I turn it off, it goes back to the original 595 00:31:05.399 --> 00:31:06.999 When we press the play button 596 00:31:06.999 --> 00:31:08.920 it doesn't get reflected if we change 597 00:31:08.920 --> 00:31:10.320 some values ​​or something 598 00:31:10.320 --> 00:31:13.959 Why? These are saved in a file 599 00:31:13.959 --> 00:31:15.109 but when there is a play button 600 00:31:15.109 --> 00:31:17.160 it is not saved in a file 601 00:31:17.160 --> 00:31:20.560 So, this exists only temporarily 602 00:31:20.560 --> 00:31:23.600 while playing the data 603 00:31:23.600 --> 00:31:26.959 Then, if you want these saved in this way to be saved 604 00:31:26.959 --> 00:31:29.640 you will have to learn the concept of saving later 605 00:31:29.640 --> 00:31:32.453 We will work on that in the beta version 606 00:31:34.760 --> 00:31:36.925 I have tried firing bullets like this 607 00:31:37.575 --> 00:31:41.367 Making Enemy Movement 608 00:31:41.880 --> 00:31:46.119 Then, let's try making an enemy move 609 00:31:46.119 --> 00:31:48.239 First, to move an enemy, you need an enemy 610 00:31:48.239 --> 00:31:52.000 So, let's make an enemy first 611 00:31:52.000 --> 00:31:58.079 In Hierarchy, press + and select Cube from 3D Object 612 00:31:58.079 --> 00:32:00.839 I'll call it Enemy 613 00:32:00.839 --> 00:32:03.600 I don't know if you noticed 614 00:32:03.600 --> 00:32:08.519 but we're doing the same process from the player 615 00:32:08.519 --> 00:32:09.880 to the bullets to the Enemy 616 00:32:09.880 --> 00:32:11.679 What do you do first? 617 00:32:11.679 --> 00:32:14.320 Make a game object 618 00:32:14.320 --> 00:32:16.399 In Hierarchy, create a cube 619 00:32:16.399 --> 00:32:20.720 create a script, assign the script 620 00:32:20.720 --> 00:32:22.320 then code 621 00:32:22.320 --> 00:32:25.480 and continue creating content with this flow 622 00:32:25.480 --> 00:32:29.279 The most difficult part of creating content with Unity is that 623 00:32:29.279 --> 00:32:30.880 you can learn each function individually 624 00:32:30.880 --> 00:32:33.760 However, you may have difficulty figuring out 625 00:32:33.760 --> 00:32:35.160 how to start and create content 626 00:32:35.160 --> 00:32:36.760 How do you do that? 627 00:32:36.760 --> 00:32:38.279 Just follow this 628 00:32:38.279 --> 00:32:39.320 What do you do first? 629 00:32:39.320 --> 00:32:42.959 Create a game object, a cube 630 00:32:42.959 --> 00:32:46.399 create a script for it, assign it 631 00:32:46.399 --> 00:32:48.749 Assign the script only to the game object 632 00:32:48.749 --> 00:32:51.480 that needs control 633 00:32:51.480 --> 00:32:54.440 You can continue to create characters 634 00:32:54.440 --> 00:32:57.440 with this flow 635 00:32:57.440 --> 00:32:59.200 Now that the Enemy has been created 636 00:32:59.200 --> 00:33:01.720 I will assign a script 637 00:33:01.720 --> 00:33:05.679 Before that, I will first set the transform position to 0, 0, 0 638 00:33:05.679 --> 00:33:08.079 and I will put it on top like this 639 00:33:08.079 --> 00:33:09.729 So, I'm going to create an enemy 640 00:33:09.729 --> 00:33:12.440 that falls down 641 00:33:12.440 --> 00:33:17.399 In the Enemy Scripts 642 00:33:17.399 --> 00:33:23.160 I will put "Enemy" as the name 643 00:33:23.160 --> 00:33:28.480 in the C# Script, like this 644 00:33:28.480 --> 00:33:30.799 Then, the Enemy will be created 645 00:33:30.799 --> 00:33:32.959 and I'll drag and drop it 646 00:33:32.959 --> 00:33:36.640 onto the Enemy game object 647 00:33:36.640 --> 00:33:39.559 Now, let's edit the script 648 00:33:39.559 --> 00:33:41.079 Here's the Enemy script 649 00:33:41.079 --> 00:33:42.160 You can click here 650 00:33:42.160 --> 00:33:44.248 or double-click here to open it 651 00:33:48.030 --> 00:33:52.254 When the Visual Studio 652 00:33:52.254 --> 00:33:54.959 for editing Enemy opens like this 653 00:33:54.959 --> 00:33:56.160 what I want to do here is 654 00:33:56.160 --> 00:33:59.679 if the bullet keeps going up 655 00:33:59.679 --> 00:34:04.359 I want the Enemy to keep moving down 656 00:34:04.359 --> 00:34:06.589 What do we need here? 657 00:34:09.440 --> 00:34:12.399 It's the movement speed 658 00:34:12.399 --> 00:34:15.760 So, public float speed 659 00:34:15.760 --> 00:34:18.483 Let's set this to the same speed as the Player 660 00:34:21.928 --> 00:34:25.320 And this content that we want to keep moving down 661 00:34:25.320 --> 00:34:26.720 we have to keep moving 662 00:34:26.720 --> 00:34:29.880 so we'll go into Update 663 00:34:29.880 --> 00:34:34.079 It's the same, right? It finds the direction and moves in that direction 664 00:34:34.079 --> 00:34:41.720 So, this puts dir 665 00:34:41.720 --> 00:34:43.720 in Vector3, and what's the direction? 666 00:34:43.720 --> 00:34:48.799 If you put Down in Vector3, it means down 667 00:34:48.799 --> 00:34:49.839 And then we want to move 668 00:34:49.839 --> 00:34:53.320 I said that P=P0+vt can be used at once 669 00:34:53.320 --> 00:34:59.927 What about the position of the transform? 670 00:34:59.927 --> 00:35:06.199 transform.position = dir * speed * Time.deltaTime 671 00:35:06.199 --> 00:35:08.599 You can do this, but how about this? 672 00:35:08.599 --> 00:35:11.880 t simply updates the current position 673 00:35:11.880 --> 00:35:14.030 It's just P=vt 674 00:35:14.030 --> 00:35:17.630 For this to function normally, P=P0+ 675 00:35:17.630 --> 00:35:22.305 you can do it like this 676 00:35:22.305 --> 00:35:25.055 What do you think? P0+vt 677 00:35:25.055 --> 00:35:28.799 But since this is also a language, it can be abbreviated 678 00:35:28.799 --> 00:35:31.099 Just like we say teacher as T 679 00:35:31.099 --> 00:35:33.749 and food waste as FW 680 00:35:33.749 --> 00:35:38.039 This can also be abbreviated like this 681 00:35:38.039 --> 00:35:43.558 If we do this, it becomes P=P0+vt 682 00:35:43.558 --> 00:35:47.158 Likewise, if we go to Bullet 683 00:35:47.158 --> 00:35:49.358 it is also like this 684 00:35:49.358 --> 00:35:51.840 We can abbreviate this part 685 00:35:51.840 --> 00:35:55.948 In Bullet, we can write += like this 686 00:35:58.200 --> 00:36:02.050 Right? So in Enemy or bullet 687 00:36:02.050 --> 00:36:05.900 or P=P0+vt, you can do the transformation 688 00:36:05.900 --> 00:36:08.360 by adding like this 689 00:36:08.360 --> 00:36:09.447 Save it 690 00:36:14.477 --> 00:36:21.096 If you press the play button, you can create 691 00:36:21.096 --> 00:36:24.951 an enemy that comes down 692 00:36:24.951 --> 00:36:29.201 You can create an enemy that comes down like this 693 00:36:29.201 --> 00:36:32.051 Let's use vectors a little more 694 00:36:32.051 --> 00:36:35.687 and write code to make this enemy move 695 00:36:35.687 --> 00:36:38.487 toward the player 696 00:36:38.487 --> 00:36:41.751 We can use vector subtraction, right? 697 00:36:41.751 --> 00:36:46.635 So what we want to do this time is not to go down 698 00:36:50.839 --> 00:36:52.391 but to continue 699 00:36:55.400 --> 00:37:00.500 moving towards the target 700 00:37:00.500 --> 00:37:03.480 Then, what else do we need besides the required movement speed? 701 00:37:03.480 --> 00:37:06.146 We need a target 702 00:37:08.199 --> 00:37:11.899 This target is public 703 00:37:11.899 --> 00:37:15.049 The target is a player in the world 704 00:37:15.049 --> 00:37:18.679 This is a game object 705 00:37:18.679 --> 00:37:22.055 So, let's put GameObject here 706 00:37:24.399 --> 00:37:28.449 Okay, so you can put public GameObject followed by the target 707 00:37:28.449 --> 00:37:31.960 Ultimately, we need 708 00:37:31.960 --> 00:37:35.510 not just the game object but also the location of this target 709 00:37:35.510 --> 00:37:37.410 Who has the location? 710 00:37:37.410 --> 00:37:39.110 The one that has the location of the game object 711 00:37:39.110 --> 00:37:41.360 is Transform 712 00:37:41.360 --> 00:37:45.320 So we only need to know this player's legs 713 00:37:45.320 --> 00:37:46.568 Where are the legs, right? 714 00:37:49.597 --> 00:37:52.780 Here is instructor Lee Young-ho 715 00:37:52.780 --> 00:37:56.720 There is instructor Lee Young-ho, but if I don't know the entire 716 00:37:56.720 --> 00:37:59.770 but the bridge's current location 717 00:37:59.770 --> 00:38:01.920 I can monitor the bridge 718 00:38:01.920 --> 00:38:03.800 and get its location 719 00:38:03.800 --> 00:38:07.900 So, I only need to know about this component called Transform 720 00:38:07.900 --> 00:38:11.479 So I can put GameObject here 721 00:38:11.479 --> 00:38:13.779 but I can also put Transform like this 722 00:38:13.779 --> 00:38:15.879 I just need to remember 723 00:38:15.879 --> 00:38:17.417 this Enemy's Transform 724 00:38:20.023 --> 00:38:22.573 So if I save it like this 725 00:38:22.573 --> 00:38:25.639 and go to Enemy, the target will be exposed 726 00:38:25.639 --> 00:38:27.555 here is Transform here 727 00:38:27.555 --> 00:38:29.405 and I will show you an important concept here 728 00:38:29.405 --> 00:38:32.153 The player here is a game object 729 00:38:32.153 --> 00:38:35.453 I want the Enemy to follow the game object 730 00:38:35.453 --> 00:38:37.303 To be clear 731 00:38:37.303 --> 00:38:39.320 this Transform in Player 732 00:38:39.320 --> 00:38:41.770 needs to go into Enemy 733 00:38:41.770 --> 00:38:43.770 But you can put it like this 734 00:38:43.770 --> 00:38:46.170 If I grab the player, grab the game object 735 00:38:46.170 --> 00:38:47.839 and put it into this target 736 00:38:47.839 --> 00:38:49.289 it wants to Transform 737 00:38:49.289 --> 00:38:51.139 so I put the game object called Player 738 00:38:51.139 --> 00:38:54.039 Then, the Player's Transform 739 00:38:54.039 --> 00:38:55.419 is automatically assigned like this 740 00:38:55.419 --> 00:38:57.869 Unity has such a great 741 00:38:57.869 --> 00:39:00.818 User Experience 742 00:39:00.818 --> 00:39:06.398 It even automatically assigns the player transform 743 00:39:06.398 --> 00:39:09.760 So, we set the target for the enemy 744 00:39:09.760 --> 00:39:12.880 Then, since we want to keep moving towards the target 745 00:39:12.880 --> 00:39:17.499 the player will be in here 746 00:39:17.499 --> 00:39:19.899 Then, let's find the direction 747 00:39:19.899 --> 00:39:21.559 to go towards this target 748 00:39:21.559 --> 00:39:25.294 Not down, now it's the target 749 00:39:28.660 --> 00:39:33.400 How do we find the direction towards the target? 750 00:39:33.400 --> 00:39:39.480 Target-Me, one of the properties in the target is position 751 00:39:39.480 --> 00:39:41.160 We need the position 752 00:39:41.160 --> 00:39:42.910 -Me, my position 753 00:39:42.910 --> 00:39:45.279 can be written as transform.position 754 00:39:45.279 --> 00:39:48.829 Then, Target-Me 755 00:39:48.829 --> 00:39:51.229 can find the vector 756 00:39:51.229 --> 00:39:53.759 that I'm heading toward the target 757 00:39:53.759 --> 00:39:58.680 But we can't just use the entire path 758 00:39:58.680 --> 00:40:03.269 How? We set the size of this vector like this 759 00:40:03.269 --> 00:40:04.669 and move at my speed 760 00:40:04.669 --> 00:40:07.400 This act of making the size of the vector 1 761 00:40:07.400 --> 00:40:09.400 is called Normalize 762 00:40:09.400 --> 00:40:12.950 So, if we call the function Normalize 763 00:40:12.950 --> 00:40:17.040 for this direction 764 00:40:17.040 --> 00:40:19.968 what happens to the size of this direction we found? 765 00:40:19.968 --> 00:40:21.246 We make it 1 766 00:40:23.867 --> 00:40:27.559 If we do this, there will be no change in that direction 767 00:40:27.559 --> 00:40:31.519 Let's save it like this and go back and look 768 00:40:31.519 --> 00:40:33.080 Let's press the play button 769 00:40:33.080 --> 00:40:36.830 Then, the enemy will continue to follow me 770 00:40:36.830 --> 00:40:40.160 as I move 771 00:40:40.160 --> 00:40:44.060 Do you see? You can make an enemy 772 00:40:44.060 --> 00:40:45.994 that follows the player like this 773 00:40:48.954 --> 00:40:51.804 Then, it will continue to follow me like this 774 00:40:51.804 --> 00:40:53.854 but I will change it 775 00:40:53.854 --> 00:40:55.639 so that it only follows me once when I am born 776 00:40:55.639 --> 00:40:57.439 Once when I am born 777 00:41:01.765 --> 00:41:07.415 I want to find the direction in which I was born 778 00:41:07.415 --> 00:41:12.014 and keep moving in that direction 779 00:41:12.014 --> 00:41:14.759 I want to keep moving in that direction 780 00:41:14.759 --> 00:41:16.859 Instead of continuing to move towards the target 781 00:41:16.859 --> 00:41:18.399 What happens then? 782 00:41:18.399 --> 00:41:20.839 I need to find the direction once when I am born 783 00:41:20.839 --> 00:41:23.240 It's not something you keep looking for as you live 784 00:41:23.240 --> 00:41:25.320 How do you look for it? 785 00:41:25.320 --> 00:41:27.759 Since the time of birth is the Start, let's do it here 786 00:41:27.759 --> 00:41:32.199 But we can't use the dir here 787 00:41:32.199 --> 00:41:34.606 This variable in Start 788 00:41:34.606 --> 00:41:37.124 is called a local variable 789 00:41:37.124 --> 00:41:40.374 In Update, we can't access this local variable 790 00:41:40.374 --> 00:41:42.559 in another function 791 00:41:42.559 --> 00:41:45.000 Then where should I put it so that I can access it? 792 00:41:45.000 --> 00:41:48.550 You have to register it globally as an attribute 793 00:41:48.550 --> 00:41:49.679 to use it 794 00:41:49.679 --> 00:41:52.529 So let's put the dir of the Vector here 795 00:41:52.529 --> 00:41:56.639 in the attribute section like this 796 00:41:56.639 --> 00:42:00.189 I'll process them like this so they use 797 00:42:00.189 --> 00:42:02.440 the dir I registered here 798 00:42:02.440 --> 00:42:05.520 Then, this one has the lights on, right? 799 00:42:05.520 --> 00:42:07.520 They'll all be the same 800 00:42:07.520 --> 00:42:12.600 So when it's born, it gets a direction once 801 00:42:12.600 --> 00:42:17.360 and wants to keep moving in that direction 802 00:42:17.360 --> 00:42:19.223 This one gets a direction when it's born 803 00:42:25.599 --> 00:42:28.505 It wants to keep moving 804 00:42:30.960 --> 00:42:34.160 So let's save it, and when it's born, it gets it once 805 00:42:34.160 --> 00:42:36.960 and wants to keep moving in that direction 806 00:42:36.960 --> 00:42:38.399 I'll go and try it 807 00:42:38.399 --> 00:42:41.759 Then, I'll put it on the side like this so it's noticeable 808 00:42:41.759 --> 00:42:44.338 When I press the play button, even if I dodge 809 00:42:44.338 --> 00:42:46.743 this one will keep moving in the direction 810 00:42:46.743 --> 00:42:48.692 it initially got 811 00:42:52.559 --> 00:42:57.279 This is how the Enemy was created 812 00:42:57.279 --> 00:42:59.279 If the enemy is made like this 813 00:42:59.279 --> 00:43:01.160 some guys will come down 814 00:43:01.160 --> 00:43:03.610 and some will go towards the target 815 00:43:03.610 --> 00:43:05.399 which may be necessary 816 00:43:05.399 --> 00:43:08.599 So, let's implement it like this 817 00:43:08.599 --> 00:43:11.440 to set it randomly 818 00:43:11.440 --> 00:43:17.390 So randomly, with a 30% probability 819 00:43:17.390 --> 00:43:19.480 some guys will go towards the target 820 00:43:19.480 --> 00:43:23.200 and others will just go down 821 00:43:23.200 --> 00:43:26.250 Then, if they all move towards the target unconditionally 822 00:43:26.250 --> 00:43:28.168 it will be difficult for the player 823 00:43:28.168 --> 00:43:32.720 So let's give them this kind of variation 824 00:43:32.720 --> 00:43:35.520 Then, when they are born, the content will be entered 825 00:43:35.520 --> 00:43:37.880 when they find this direction 826 00:43:37.880 --> 00:43:39.330 How are we going to do it? 827 00:43:39.330 --> 00:43:49.399 Find the direction towards the target with a 30% probability 828 00:43:49.399 --> 00:43:51.109 otherwise, if it's outside of 30% 829 00:43:51.109 --> 00:43:59.497 Just set the direction down 830 00:43:59.497 --> 00:44:02.822 Let's put it like this 831 00:44:02.822 --> 00:44:05.839 Then, we can get a 30% probability like this 832 00:44:05.839 --> 00:44:08.000 First, let's get the probability 833 00:44:08.000 --> 00:44:18.499 Let's put in int for the probability 834 00:44:18.499 --> 00:44:20.440 Let's put in percent 835 00:44:20.440 --> 00:44:26.599 If you look at Random, there's something called Range 836 00:44:29.813 --> 00:44:31.263 There's also RandomRange 837 00:44:31.263 --> 00:44:32.799 but it's not used here 838 00:44:32.799 --> 00:44:33.899 Let's put it as Range 839 00:44:33.899 --> 00:44:39.559 Let's put in 1 to 10 here 840 00:44:39.559 --> 00:44:44.600 So, what does this Range look like? 841 00:44:44.600 --> 00:44:48.760 It says maxExclusive 842 00:44:48.760 --> 00:44:52.399 If you go inside, it looks like this 843 00:44:52.399 --> 00:44:57.000 It goes int and works 844 00:44:57.000 --> 00:45:03.320 So we're going to use it here 845 00:45:03.320 --> 00:45:06.119 Let's get percent from 1 to 10 846 00:45:06.119 --> 00:45:11.359 Then how do we say that this has a 30% probability? 847 00:45:11.359 --> 00:45:14.110 If it's less than 3, right? Then it's 30% 848 00:45:14.110 --> 00:45:16.600 If it's greater than 3? It's a different probability 849 00:45:16.600 --> 00:45:27.839 So the probability of 30% is it(percent <= 3) 850 00:45:27.839 --> 00:45:30.320 It includes 3, right? Because it's 1,2,3 851 00:45:30.320 --> 00:45:33.440 Then what do we do? 852 00:45:33.440 --> 00:45:37.540 In the direction of the target like this 853 00:45:37.540 --> 00:45:41.200 Let's get it in the direction of the target 854 00:45:41.200 --> 00:45:44.006 This part is the 30% probability 855 00:45:48.333 --> 00:45:51.799 Otherwise, what do we do? Since we just did it down 856 00:45:51.799 --> 00:45:57.920 we did else like this, so it's just down 857 00:45:57.920 --> 00:46:04.820 So you can do this dir = Vector3.down 858 00:46:04.820 --> 00:46:06.119 You can do like this 859 00:46:06.119 --> 00:46:10.978 Should we save it and go and take a look? 860 00:46:10.978 --> 00:46:14.228 If you press the play button 861 00:46:14.228 --> 00:46:18.328 you can see that this moves down or towards the target 862 00:46:18.328 --> 00:46:21.239 with a 30% probability 863 00:46:21.239 --> 00:46:25.235 We've learned about the enemy's movement up to here 864 00:46:26.730 --> 00:46:30.000 Let's summarize what we learned in this section 865 00:46:30.000 --> 00:46:31.400 The first learning content 866 00:46:31.400 --> 00:46:33.839 was implementing bullet movement 867 00:46:33.839 --> 00:46:37.389 We created a Bullet game object and wrote a C# script 868 00:46:37.389 --> 00:46:40.559 to move it up 869 00:46:40.559 --> 00:46:44.239 The second learning content was implementing shooting bullets 870 00:46:44.239 --> 00:46:46.289 We created Bullet Prefabs 871 00:46:46.289 --> 00:46:47.789 and used the Player Fire script 872 00:46:47.789 --> 00:46:50.439 to fire bullets 873 00:46:50.439 --> 00:46:53.239 when the user presses the fire button 874 00:46:53.239 --> 00:46:56.359 The last learning content was creating enemy movement 875 00:46:56.359 --> 00:46:57.909 We created an enemy object 876 00:46:57.909 --> 00:47:01.868 and wrote a script to move it down 877 00:47:01.868 --> 00:47:03.792 Thank you for your hard work 878 00:47:04.905 --> 00:47:05.746 Create a bullet movement Create a bullet and set its position 879 00:47:05.746 --> 00:47:06.605 Create [+] - [3D Object] - [Cube] in the hierarchy and rename it to Bullet Change the position and size of the bullet in the Bullet's Transform 880 00:47:06.605 --> 00:47:07.355 Create and assign Bullet script Create [Scripts] - [+] - [C# Script] in the project window and rename it to Bullet 881 00:47:07.355 --> 00:47:08.186 Drag and drop the Bullet script to the Bullet game object's component 882 00:47:08.186 --> 00:47:08.986 Implement Bullet movement script Create a speed variable with public access modifier so that it is exposed on the Unity editor 883 00:47:08.986 --> 00:47:09.825 Add implementation to the Update function so that it is continuously called Find the up direction and implement the movement part using the movement formula P = P0 + vt 884 00:47:09.825 --> 00:47:10.775 Create a bullet launcher Create and assign a PlayerFire script Create [+] - [C# Script] in the Project window and rename it to PlayerFire 885 00:47:10.775 --> 00:47:11.575 Drag and drop the PlayerFire script as a component of the Player game object Create and assign Bullet Prefabs 886 00:47:11.575 --> 00:47:12.375 Create a folder in the Project window and rename it to Prefabs Drag and drop the Bullet object in the hierarchy to the Prefabs folder in the Project window 887 00:47:12.375 --> 00:47:13.325 Remove Bullet from the scene and assign Bullet Prefabs to the Bullet Factory property of PlayerFire Create a gun barrel and assign properties 888 00:47:13.325 --> 00:47:14.125 Select the Player object, right-click, select Create Empty, and rename the empty game object registered as a child to FirePosition 889 00:47:14.125 --> 00:47:14.963 Assign the FirePosition object to the Player's PlayerFire script 890 00:47:14.963 --> 00:47:16.213 Processing bullet firing input We need to produce a bullet every time the fire button is pressed, so input it in the Update function 891 00:47:16.213 --> 00:47:17.413 Use the GetButtonDown function that returns True when the button is pressed When the left mouse or left Ctrl button is clicked, input processing is 'Fire1' 892 00:47:17.413 --> 00:47:18.613 When bulletFactory is input as an argument to the Instantiate function, a bullet is generated 893 00:47:18.613 --> 00:47:19.853 Assign the position of the muzzle, firePosition, declared as a property to the created bullet object 894 00:47:19.853 --> 00:47:21.553 Enemy Movement Production Create Enemy object and assign script Create [+] - [3D Object] - [Cube] in the hierarchy and rename it to Enemy 895 00:47:21.553 --> 00:47:23.103 Create [Scripts folder] - [+] - [C# Script] in the project window and rename it to Enemy Drag and drop the Enemy script to the Enemy game object's component 896 00:47:23.103 --> 00:47:24.648 Write movement code Declare the movement speed property, find the direction, and implement the code with the movement formula