WEBVTT 1 00:00:06.364 --> 00:00:09.869 Game Advanced Alpha Type Version 1 2 00:00:27.379 --> 00:00:28.924 Hello everyone 3 00:00:28.924 --> 00:00:31.379 This is Kim Hyunjin of FPS game development 4 00:00:31.379 --> 00:00:34.684 In this lecture, we will learn how to apply 5 00:00:34.684 --> 00:00:37.666 the model that can be downloaded 6 00:00:37.666 --> 00:00:40.950 through the Asset Store to a enemy that is in a capsule 7 00:00:40.950 --> 00:00:44.649 And utilizing Animator and the animation clip 8 00:00:44.649 --> 00:00:48.180 I will implement so that the right animation can be executed 9 00:00:48.549 --> 00:00:52.648 Application of an enemy model 10 00:00:52.648 --> 00:00:57.713 This time, the capsule based enemy 11 00:00:57.713 --> 00:01:05.077 will be changed into a zombie shaped model from the Asset Store 12 00:01:07.840 --> 00:01:11.546 I will select the Window menu from the upper editor menu 13 00:01:11.546 --> 00:01:14.588 Press on the Asset Store button 14 00:01:14.588 --> 00:01:18.768 And then press the Search online button 15 00:01:20.896 --> 00:01:23.409 When the Asset Store website pops up 16 00:01:23.409 --> 00:01:26.718 I will search for the word zombie in the search engine 17 00:01:29.005 --> 00:01:30.867 Select the zombie asset 18 00:01:34.568 --> 00:01:38.561 Next, press on the add to the asset button 19 00:01:38.561 --> 00:01:39.556 Please confirm it 20 00:01:45.429 --> 00:01:49.491 Then chose the open button from the unity 21 00:01:49.491 --> 00:01:52.157 And press on the open button from the unity editor 22 00:01:54.593 --> 00:01:57.065 As the package manager opens up 23 00:01:57.065 --> 00:02:00.327 you will be able to see the zombie page 24 00:02:00.327 --> 00:02:02.336 Press the download button over here 25 00:02:05.980 --> 00:02:10.668 If it has been downloaded, press on the import button 26 00:02:10.668 --> 00:02:12.630 Next, when the browser window opens up 27 00:02:12.630 --> 00:02:14.376 Press the import button which is placed in the bottom right 28 00:02:17.857 --> 00:02:21.774 If the zombie isn't selected like this 29 00:02:21.774 --> 00:02:24.937 in the package manger 30 00:02:24.937 --> 00:02:26.929 Next to the + button in the upper left side 31 00:02:26.929 --> 00:02:30.644 There is a menu called package unity registry 32 00:02:30.644 --> 00:02:33.439 If you select it, it will dropdown like so 33 00:02:33.439 --> 00:02:37.401 Choose the My Assets category from over here 34 00:02:37.401 --> 00:02:40.404 This category holds all the assets 35 00:02:40.404 --> 00:02:44.157 that we have bought from the Asset Store 36 00:02:44.157 --> 00:02:46.883 So select My Assets and 37 00:02:46.883 --> 00:02:50.977 and if we search zombie in the search engine 38 00:02:50.977 --> 00:02:53.777 Out of the assets that we have bought 39 00:02:53.777 --> 00:02:56.758 It will look for the zombie 40 00:02:56.758 --> 00:02:58.375 You can add over here as well 41 00:03:00.369 --> 00:03:05.014 If it has been added, there will be 42 00:03:05.014 --> 00:03:06.908 a zombie folder in the project window 43 00:03:09.037 --> 00:03:13.149 Select FBXs folder over here 44 00:03:13.149 --> 00:03:15.849 I will use Zombie 1 45 00:03:15.849 --> 00:03:19.117 Drag Zombie1 46 00:03:19.117 --> 00:03:22.079 and I will put it in Enemy 47 00:03:22.079 --> 00:03:24.249 Drag and attach it to Enemy 48 00:03:26.878 --> 00:03:30.667 But as you can see, the zombie's color is pink 49 00:03:30.667 --> 00:03:34.278 This means there is an error in the material 50 00:03:34.278 --> 00:03:37.857 When we created the project 51 00:03:37.857 --> 00:03:41.614 We used URP mode 52 00:03:43.500 --> 00:03:46.031 So from the Asset store 53 00:03:46.031 --> 00:03:48.054 If you have received a certain asset 54 00:03:48.054 --> 00:03:49.880 and it is in the color pink 55 00:03:49.880 --> 00:03:51.718 The material that is used over here 56 00:03:51.718 --> 00:03:53.036 needs to be revised a little 57 00:03:54.989 --> 00:03:58.787 I will choose the Materials folder that is below the zombie folder 58 00:03:58.787 --> 00:04:02.406 Then there will be two materials 59 00:04:02.406 --> 00:04:06.487 Select both of the materials. All of them 60 00:04:06.487 --> 00:04:11.018 And select the Edit menu that is on the upper left side 61 00:04:11.018 --> 00:04:15.528 If you leave the mouse on the Rendering menu that is in the bottom 62 00:04:15.528 --> 00:04:18.259 It will expand to the right like so 63 00:04:18.259 --> 00:04:22.210 Select the Materials menu 64 00:04:22.210 --> 00:04:26.497 And Convert Selected Built in 65 00:04:26.497 --> 00:04:30.468 If you choose the menu called Materials to URP 66 00:04:30.468 --> 00:04:32.857 It allows this material to be 67 00:04:32.857 --> 00:04:37.199 revised according to the form of the URP 68 00:04:37.199 --> 00:04:38.115 Press it 69 00:04:40.028 --> 00:04:41.568 Then it will pop up in a window 70 00:04:41.568 --> 00:04:45.594 Press on the Proceed button over here 71 00:04:48.978 --> 00:04:53.545 Then the material will be revised like so 72 00:04:53.545 --> 00:04:56.833 the shape of the zombie will show up in a normal way 73 00:04:56.833 --> 00:04:57.698 as you can see over here 74 00:05:00.148 --> 00:05:04.385 Now, I will hide the capsule that is in the color red 75 00:05:04.385 --> 00:05:08.129 Like this, I will make sure the zombie shaped model 76 00:05:08.129 --> 00:05:11.947 can be clearly seen 77 00:05:11.947 --> 00:05:15.259 Select on Enemy GameObject 78 00:05:15.259 --> 00:05:18.252 From the Inspector, I will inactivate 79 00:05:18.252 --> 00:05:20.407 a component called Mesh Renderer 80 00:05:22.749 --> 00:05:27.019 Then you aren't able to see the shape of the capsule, right? 81 00:05:27.019 --> 00:05:31.289 And the zombie is up in the air so 82 00:05:31.289 --> 00:05:37.448 Choose the zombie model that was inside the Enemy 83 00:05:37.448 --> 00:05:40.725 And the y value of the Inspector will be chosen as -1 84 00:05:43.519 --> 00:05:46.799 Then you can see that it stands on the ground like so 85 00:05:49.238 --> 00:05:51.730 When you develop the project for the first time 86 00:05:51.730 --> 00:05:56.639 The functions should be implemented using the basic shapes 87 00:05:56.639 --> 00:06:02.549 And later on, getting help from the asset store 88 00:06:02.549 --> 00:06:05.591 or the art department 89 00:06:05.591 --> 00:06:09.380 The progress of changing the basic shapes into 90 00:06:09.380 --> 00:06:11.524 beautiful and cool forms can be proceeded 91 00:06:12.188 --> 00:06:16.811 Enemy Animation 92 00:06:16.811 --> 00:06:20.483 Now, the zombie models will be applied 93 00:06:20.483 --> 00:06:24.549 so that the animation for each condition 94 00:06:24.549 --> 00:06:26.104 could be implemented 95 00:06:29.808 --> 00:06:34.630 For the animation to be applied to this model 96 00:06:34.630 --> 00:06:37.779 We need a component called Animator 97 00:06:37.779 --> 00:06:39.019 You can see that it is attached over here, right? 98 00:06:39.019 --> 00:06:40.858 If it isn't attached 99 00:06:40.858 --> 00:06:42.984 Press the Add component button 100 00:06:42.984 --> 00:06:45.644 search for Animator 101 00:06:45.644 --> 00:06:46.666 and then add it 102 00:06:48.557 --> 00:06:52.573 And select the zombie folder that we have downloaded 103 00:06:52.573 --> 00:06:55.959 Go into the Animations folder 104 00:06:55.959 --> 00:07:01.008 There are several animation files 105 00:07:01.008 --> 00:07:03.319 Using these certain files 106 00:07:03.319 --> 00:07:08.039 We will enable the zombie model to execute the animation 107 00:07:08.039 --> 00:07:11.816 First, we need to generate a file 108 00:07:11.816 --> 00:07:14.089 Select the Assets folder 109 00:07:14.089 --> 00:07:17.109 and create another folder 110 00:07:17.109 --> 00:07:20.598 Press the + button from the project 111 00:07:20.598 --> 00:07:24.116 and let's say the name of the folder is Animations 112 00:07:27.246 --> 00:07:31.597 Then, after selecting the Animations folder 113 00:07:31.597 --> 00:07:33.946 Press the + button and 114 00:07:33.946 --> 00:07:38.227 Choose the Animator Controller menu in the middle 115 00:07:38.227 --> 00:07:40.428 Then a file like this will be generated 116 00:07:40.428 --> 00:07:47.487 I will name this file as ZombieAnim 117 00:07:49.748 --> 00:07:51.886 If you double click on the file 118 00:07:51.886 --> 00:07:53.415 the a window like this will pop up 119 00:07:53.415 --> 00:07:55.758 An animator window 120 00:07:55.758 --> 00:08:00.168 In this zombie folder that we have downloaded 121 00:08:00.168 --> 00:08:02.599 there are animation files 122 00:08:02.599 --> 00:08:06.586 Placing these files over here 123 00:08:06.586 --> 00:08:08.195 I will enable it to operate 124 00:08:10.413 --> 00:08:13.853 At first, we have divided the condition of the enemy 125 00:08:13.853 --> 00:08:16.723 and how it will transfer 126 00:08:16.723 --> 00:08:19.588 into a diagram 127 00:08:19.588 --> 00:08:23.049 Place the animation similar to this 128 00:08:23.049 --> 00:08:25.196 Transition like so 129 00:08:25.196 --> 00:08:31.076 I will set it so that the animation will change 130 00:08:31.076 --> 00:08:35.413 In this animator window, using the wheel of the mouse 131 00:08:35.413 --> 00:08:37.349 It can be expanded and shrunk 132 00:08:37.349 --> 00:08:41.421 Next, click the wheel button 133 00:08:41.421 --> 00:08:44.277 to move it around 134 00:08:44.277 --> 00:08:46.666 Make sure to remember this operating method 135 00:08:48.379 --> 00:08:50.861 First, when this Animator is operated 136 00:08:50.861 --> 00:08:55.978 It will be operated in this node called Entry 137 00:08:55.978 --> 00:08:59.609 so in this model with the Animator 138 00:08:59.609 --> 00:09:01.154 At first, what action it should take 139 00:09:01.154 --> 00:09:04.451 The animation that you want to enable 140 00:09:04.451 --> 00:09:08.205 should be left over here 141 00:09:08.205 --> 00:09:12.738 From the animation folder in the zombie folder 142 00:09:12.738 --> 00:09:15.140 we will upload an animation file 143 00:09:15.140 --> 00:09:18.649 named Z Idle 144 00:09:18.649 --> 00:09:20.048 Let's select and drag it 145 00:09:20.048 --> 00:09:21.818 It will come up like this 146 00:09:21.818 --> 00:09:25.855 If there isn't anything inside the Animator 147 00:09:25.855 --> 00:09:28.022 If there is no animation file 148 00:09:28.022 --> 00:09:33.559 It will be automatically connected to the Entry like this 149 00:09:33.559 --> 00:09:35.616 I will change the name 150 00:09:35.616 --> 00:09:39.158 After selecting this Z Idle node 151 00:09:39.158 --> 00:09:44.353 I will change it from Idle to Inspecttor 152 00:09:44.353 --> 00:09:46.748 If you play it 153 00:09:46.748 --> 00:09:51.068 The zombie won't be able to operate the animation 154 00:09:51.068 --> 00:09:56.019 Because if you select the zombie game object of the Hierarchy 155 00:09:56.019 --> 00:09:59.162 the Animator component will be attached 156 00:09:59.162 --> 00:10:03.339 In the attribute called Controller 157 00:10:03.339 --> 00:10:08.988 the Animator that we have just created should be included 158 00:10:08.988 --> 00:10:12.378 So inside the Animations folder which is in the Assets folder 159 00:10:12.378 --> 00:10:15.206 We have created the ZombieAnim 160 00:10:15.206 --> 00:10:18.575 Drag the Animator file 161 00:10:18.575 --> 00:10:22.045 and attach it over here 162 00:10:22.045 --> 00:10:24.345 We need to set it this way so that 163 00:10:24.345 --> 00:10:27.158 the animator which was in the Animator browse 164 00:10:27.158 --> 00:10:30.856 can be executed 165 00:10:33.198 --> 00:10:34.623 I will try to play this 166 00:10:37.289 --> 00:10:39.836 Since the player is too close 167 00:10:39.836 --> 00:10:41.856 It will be in a moving condition 168 00:10:41.856 --> 00:10:44.777 Place it further 169 00:10:44.777 --> 00:10:46.333 and play it once again 170 00:10:48.155 --> 00:10:51.218 Like so 171 00:10:51.218 --> 00:10:53.078 We can see that the animation which 172 00:10:53.078 --> 00:10:57.306 seems as if it is breathing is being operated 173 00:10:57.306 --> 00:10:59.787 When the player has moved closer 174 00:11:03.638 --> 00:11:05.854 The Enemy is moving, right? 175 00:11:05.854 --> 00:11:09.109 Then which animation do you think we should operate? 176 00:11:09.109 --> 00:11:10.170 The walking animation 177 00:11:10.170 --> 00:11:13.359 or the running animation 178 00:11:13.359 --> 00:11:16.203 Therefore, in this Animator file 179 00:11:16.203 --> 00:11:19.210 we will add one more animation 180 00:11:19.210 --> 00:11:20.526 Selecting the animation folder again 181 00:11:20.526 --> 00:11:23.929 which is inside the zombie folder 182 00:11:23.929 --> 00:11:28.938 An animation file called Z Run Inplace 183 00:11:28.938 --> 00:11:32.256 will be dragged on 184 00:11:32.256 --> 00:11:34.748 I will change the name 185 00:11:34.748 --> 00:11:37.508 Let's name it as Move 186 00:11:37.508 --> 00:11:40.497 If it is converted from Idle animation 187 00:11:40.497 --> 00:11:43.863 to the moving condition 188 00:11:43.863 --> 00:11:46.741 The Move animation should also be 189 00:11:46.741 --> 00:11:49.043 operated as well 190 00:11:49.043 --> 00:11:52.237 So from the node of Idle animation 191 00:11:52.237 --> 00:11:54.337 Press the key on the right 192 00:11:54.337 --> 00:11:58.840 Select a menu called Make Transition 193 00:11:58.840 --> 00:12:00.063 It is a transition 194 00:12:00.063 --> 00:12:01.577 We will create a transition 195 00:12:01.577 --> 00:12:04.008 Then, as you can see the line 196 00:12:04.008 --> 00:12:07.692 will follow the mouse point around 197 00:12:07.692 --> 00:12:10.764 Therefore, if you bring over the mouse 198 00:12:10.764 --> 00:12:12.221 to the Move animation node 199 00:12:12.221 --> 00:12:16.528 You can see that it attaches 200 00:12:16.528 --> 00:12:18.561 And click on the Move 201 00:12:18.561 --> 00:12:20.218 Then, like so 202 00:12:20.218 --> 00:12:23.644 These two nodes will be connected 203 00:12:26.387 --> 00:12:30.357 If it has been connected, I will play it 204 00:12:30.357 --> 00:12:34.477 Separate the Animator window 205 00:12:34.477 --> 00:12:38.990 so that it can both be seen at the same time 206 00:12:38.990 --> 00:12:40.536 I will change the setting 207 00:12:43.397 --> 00:12:45.975 If I play it, we can see what animation is 208 00:12:45.975 --> 00:12:50.009 being operated through the Animator 209 00:12:50.009 --> 00:12:51.826 After Idle has been operated 210 00:12:51.826 --> 00:12:53.287 it has suddenly changed to Move, right? 211 00:12:56.859 --> 00:12:58.901 Select this transition 212 00:12:58.901 --> 00:12:59.952 and it can be eliminated as well 213 00:12:59.952 --> 00:13:01.486 If we play it 214 00:13:04.559 --> 00:13:07.077 You can see the Idle is still being operated 215 00:13:09.354 --> 00:13:11.732 I will connect it once again 216 00:13:11.732 --> 00:13:14.108 And you can select this transition 217 00:13:14.108 --> 00:13:17.718 The default setting is complete, once you have selected it 218 00:13:17.718 --> 00:13:19.857 If we play it in this condition 219 00:13:19.857 --> 00:13:21.352 this Idle will be operated 220 00:13:21.352 --> 00:13:23.879 and it has passed automatically, right? 221 00:13:23.879 --> 00:13:27.035 The reason is because this menu called 222 00:13:27.035 --> 00:13:29.649 Has Exit Time was chosen 223 00:13:29.649 --> 00:13:32.806 Whether the Condition in the bottom 224 00:13:32.806 --> 00:13:34.078 is present or absent 225 00:13:34.078 --> 00:13:35.699 makes the option operate in a slightly different way 226 00:13:35.699 --> 00:13:37.430 The Condition isn't here 227 00:13:37.430 --> 00:13:40.359 therefore, this transition 228 00:13:40.359 --> 00:13:45.409 once the previous animation has been operated once 229 00:13:45.409 --> 00:13:49.159 it will automatically pass to the 230 00:13:49.159 --> 00:13:51.177 animation that is connected 231 00:13:53.679 --> 00:13:56.526 If it is left in this condition 232 00:13:56.526 --> 00:14:00.707 When it is played, the Idle will be operated once 233 00:14:00.707 --> 00:14:04.258 and the phenomenon of it moving through Move will be seen 234 00:14:04.258 --> 00:14:10.178 What we desire is when the player is close 235 00:14:10.178 --> 00:14:13.326 and the enemy is in moving condition 236 00:14:13.326 --> 00:14:16.399 That is when we want the Move animation to be operated 237 00:14:16.399 --> 00:14:19.180 So the condition that enables the passing 238 00:14:19.180 --> 00:14:22.366 needs to be set 239 00:14:22.366 --> 00:14:24.301 If you look at the Animator window 240 00:14:24.301 --> 00:14:26.454 There is the Layers and Parameter 241 00:14:26.454 --> 00:14:29.367 Select the Parameter tab 242 00:14:29.367 --> 00:14:32.220 And then this is the + button 243 00:14:32.220 --> 00:14:34.563 Press on the + button 244 00:14:34.563 --> 00:14:37.737 and select the Trigger menu 245 00:14:37.737 --> 00:14:41.549 And let's name it Move 246 00:14:41.549 --> 00:14:45.213 This Parameter can be used as a 247 00:14:45.213 --> 00:14:47.917 condition for the transition 248 00:14:47.917 --> 00:14:49.233 Select the transition 249 00:14:49.233 --> 00:14:51.175 from Idle to Move 250 00:14:51.175 --> 00:14:53.326 From the Inspector, if you look at the bottom 251 00:14:53.326 --> 00:14:55.748 There is a + button in the Condition menu 252 00:14:55.748 --> 00:14:58.901 Press the + button 253 00:14:58.901 --> 00:15:00.633 Then a Move will be 254 00:15:00.633 --> 00:15:02.829 set automatically 255 00:15:02.829 --> 00:15:04.896 Currently in this Parameter 256 00:15:04.896 --> 00:15:07.140 The Parameter called Move is the only one there 257 00:15:07.140 --> 00:15:10.477 which is why Move will be selected automatically 258 00:15:10.477 --> 00:15:12.253 If you did dropdown 259 00:15:12.253 --> 00:15:14.288 and made multiple Parameters 260 00:15:14.288 --> 00:15:17.348 You can select from here 261 00:15:17.348 --> 00:15:19.370 Previously, it had passed automatically, right? 262 00:15:19.370 --> 00:15:22.197 But now 263 00:15:22.197 --> 00:15:26.578 It doesn't pass even when the Idle is completely executed 264 00:15:26.578 --> 00:15:28.640 This condition of transition that passes over 265 00:15:28.640 --> 00:15:31.295 This Trigger called Move 266 00:15:31.295 --> 00:15:35.279 needs to be operated once in order to pass 267 00:15:35.279 --> 00:15:37.483 So whenever we want to 268 00:15:37.483 --> 00:15:42.589 we can enable the Move animation 269 00:15:42.589 --> 00:15:43.816 Through what? 270 00:15:43.816 --> 00:15:47.661 By operating this Trigger called Move 271 00:15:47.661 --> 00:15:50.141 Then, the method to operate the Trigger called Move 272 00:15:50.141 --> 00:15:52.738 needs to be learned 273 00:15:55.178 --> 00:16:00.186 It can be done through the Animator component 274 00:16:00.186 --> 00:16:02.526 Let's come back to the code 275 00:16:02.526 --> 00:16:07.039 Open up EnemyFSM script 276 00:16:07.039 --> 00:16:11.528 In the global variable, I will make a variable that 277 00:16:11.528 --> 00:16:14.757 has a Animator component 278 00:16:14.757 --> 00:16:17.998 which is attached to the zombie game object 279 00:16:17.998 --> 00:16:20.808 Animator Variable 280 00:16:24.740 --> 00:16:27.836 There is a class called Animator 281 00:16:27.836 --> 00:16:32.367 Then let's name it anim 282 00:16:32.367 --> 00:16:35.279 Through the public keyword 283 00:16:35.279 --> 00:16:38.768 we can drag and drop from the editor 284 00:16:38.768 --> 00:16:42.219 or as we brought the navigation agent 285 00:16:42.219 --> 00:16:44.342 We could also use GetComponent 286 00:16:44.342 --> 00:16:48.257 Let's bring the code over for this one 287 00:16:48.257 --> 00:16:52.917 Bring over Animator component 288 00:16:55.049 --> 00:16:58.932 We should hold it in the variable called anim that we have created 289 00:16:58.932 --> 00:17:01.489 I'll type in GetComponent 290 00:17:01.489 --> 00:17:03.179 Which component should we bring? 291 00:17:03.179 --> 00:17:06.366 The Animator component needs to be brought over 292 00:17:06.366 --> 00:17:07.057 That was what we said 293 00:17:09.249 --> 00:17:11.048 But if it is written like this 294 00:17:11.048 --> 00:17:14.728 The Animator component can't be brought over 295 00:17:14.728 --> 00:17:17.478 Go to the editor 296 00:17:17.478 --> 00:17:22.299 This component of EnemyFSM script 297 00:17:22.299 --> 00:17:25.224 It is in the Enemy game object 298 00:17:25.224 --> 00:17:27.254 So in this script 299 00:17:27.254 --> 00:17:29.709 if this GetComponent is simply used 300 00:17:29.709 --> 00:17:32.370 the components in the same line 301 00:17:32.370 --> 00:17:35.279 will be searched through this function 302 00:17:35.279 --> 00:17:40.680 So I mentioned I will find the Animator from here 303 00:17:40.680 --> 00:17:44.211 In the Enemy game object itself 304 00:17:44.211 --> 00:17:46.595 the Animator component is not attached 305 00:17:46.595 --> 00:17:48.088 So it can't be found 306 00:17:48.088 --> 00:17:49.775 Where is it? 307 00:17:49.775 --> 00:17:53.057 It is in the game object called zombie 308 00:17:53.057 --> 00:17:56.948 which is a child of the Enemy game object 309 00:17:56.948 --> 00:18:01.706 So this GetComponent cannot be simply used 310 00:18:01.706 --> 00:18:02.456 I will change it 311 00:18:04.629 --> 00:18:10.317 There is a function called 312 00:18:10.317 --> 00:18:11.194 GetComponentInChildren 313 00:18:13.350 --> 00:18:18.444 Out of the child game object 314 00:18:18.444 --> 00:18:20.166 It plays the role of 315 00:18:20.166 --> 00:18:24.458 finding the particular component 316 00:18:24.458 --> 00:18:27.302 Through this progress, the anim variable is 317 00:18:27.302 --> 00:18:33.009 stored into the Animator component 318 00:18:33.009 --> 00:18:36.233 This anim variable 319 00:18:36.233 --> 00:18:40.498 allows the Trigger to occur 320 00:18:40.498 --> 00:18:44.526 The Trigger called Move occurs when 321 00:18:44.526 --> 00:18:48.208 it is transferred to the condition called Move 322 00:18:48.208 --> 00:18:50.286 So We have already created 323 00:18:50.286 --> 00:18:52.641 the function that will be invoked 324 00:18:52.641 --> 00:18:54.883 when the condition has been transferred 325 00:18:54.883 --> 00:18:56.068 What is it? 326 00:18:56.068 --> 00:18:59.902 We have created a function called ChangeState 327 00:18:59.902 --> 00:19:02.766 So if this State is Move 328 00:19:02.766 --> 00:19:04.588 Then it will continue in the condition of Move 329 00:19:04.588 --> 00:19:06.569 What will it do then? 330 00:19:06.569 --> 00:19:11.095 It will activate Move Trigger once again 331 00:19:11.095 --> 00:19:15.000 So come over to the ChangeState function 332 00:19:15.000 --> 00:19:18.019 In this Switch case statement 333 00:19:18.019 --> 00:19:21.884 If this current CurrState is Move 334 00:19:21.884 --> 00:19:24.899 Let's activate Move Trigger 335 00:19:24.899 --> 00:19:30.416 Hey anim, out of the functions that you have 336 00:19:30.416 --> 00:19:33.419 There is a function called SetTrigger 337 00:19:33.419 --> 00:19:35.539 Through this function 338 00:19:35.539 --> 00:19:37.788 the Trigger will be activated 339 00:19:37.788 --> 00:19:42.208 Open up the brackets and write down the name of the 340 00:19:42.208 --> 00:19:44.658 Trigger Parameter that you would like to activate 341 00:19:44.658 --> 00:19:48.822 We have set the name as Move 342 00:19:48.822 --> 00:19:49.947 So Move 343 00:19:52.489 --> 00:19:54.386 Come back to the editor 344 00:19:54.386 --> 00:19:57.659 and I will try to play it once again 345 00:19:57.659 --> 00:20:00.120 The zombie is in an Idle state 346 00:20:00.120 --> 00:20:03.039 I will adjust the player 347 00:20:03.039 --> 00:20:04.965 and move closer to it 348 00:20:04.965 --> 00:20:08.389 Then it runs over, right? 349 00:20:08.389 --> 00:20:11.315 But it will continue to Move even in an attacking state 350 00:20:11.315 --> 00:20:13.296 So what should we do now? 351 00:20:13.296 --> 00:20:15.138 When it is converting to an attacking state 352 00:20:15.138 --> 00:20:17.627 We have to let the attack animation occur once gain 353 00:20:20.009 --> 00:20:21.867 But prior to that, there is a 354 00:20:21.867 --> 00:20:24.806 slight error over here 355 00:20:24.806 --> 00:20:27.429 I will try to play again 356 00:20:27.429 --> 00:20:29.325 Into a Move state 357 00:20:29.325 --> 00:20:33.063 I will try to create thee 358 00:20:33.063 --> 00:20:34.845 beginning stage of the Idle animation 359 00:20:37.050 --> 00:20:39.175 And move over to the end of the Idle animation 360 00:20:39.175 --> 00:20:43.587 Then, during the Idle animation 361 00:20:43.587 --> 00:20:46.558 there will be a moving stage 362 00:20:46.558 --> 00:20:48.851 It is because of this transition 363 00:20:48.851 --> 00:20:51.958 Select the transition 364 00:20:51.958 --> 00:20:54.100 and the Has Exit Time will have a check mark next to it 365 00:20:54.100 --> 00:20:55.904 This is why 366 00:20:55.904 --> 00:20:58.648 At first, when Has Exit Time 367 00:20:58.648 --> 00:21:00.071 had a check mark next to it 368 00:21:00.071 --> 00:21:02.689 I mentioned that depending on the existence of the Condition 369 00:21:02.689 --> 00:21:04.918 it would operate differently 370 00:21:04.918 --> 00:21:07.017 If the Condition is not there 371 00:21:07.017 --> 00:21:08.275 the Idle will operate 372 00:21:08.275 --> 00:21:10.377 and the automatically connected 373 00:21:10.377 --> 00:21:13.159 animation will operate 374 00:21:13.159 --> 00:21:15.997 But after I have added a Condition 375 00:21:15.997 --> 00:21:17.584 it didn't pass automatically, right? 376 00:21:17.584 --> 00:21:18.639 When did it pass? 377 00:21:18.639 --> 00:21:21.150 It passed after a Trigger called Move has activated 378 00:21:21.150 --> 00:21:23.530 But there is one more over here 379 00:21:23.530 --> 00:21:25.671 Has Exit Time has a check mark next to it 380 00:21:25.671 --> 00:21:28.029 So it won't pass right after the Trigger has been activated 381 00:21:28.029 --> 00:21:28.888 When? 382 00:21:28.888 --> 00:21:32.555 When this Idle is completely finished 383 00:21:32.555 --> 00:21:35.818 When the Trigger activates at that moment 384 00:21:35.818 --> 00:21:38.353 It will pass over to Move 385 00:21:38.353 --> 00:21:41.608 Therefore, in the condition of Move 386 00:21:41.608 --> 00:21:43.609 Let's say the Idle animation 387 00:21:43.609 --> 00:21:45.909 was in its beginning stage 388 00:21:45.909 --> 00:21:49.205 The Trigger has been already activated 389 00:21:49.205 --> 00:21:50.332 But it cannot pass 390 00:21:50.332 --> 00:21:50.824 Why? 391 00:21:50.824 --> 00:21:52.642 Because of the option that Has Exit Time has 392 00:21:52.642 --> 00:21:54.589 So after the Idle is completely finished 393 00:21:54.589 --> 00:21:55.859 Ah the Trigger has been activated 394 00:21:55.859 --> 00:21:57.950 That is when it can be passed over 395 00:21:57.950 --> 00:22:00.228 So according to the code 396 00:22:00.228 --> 00:22:02.505 It is moving toward the play 397 00:22:02.505 --> 00:22:06.458 As the Idle animation proceeds 398 00:22:06.458 --> 00:22:10.097 the animation will be able to see it move 399 00:22:10.097 --> 00:22:13.589 So let's make a check mark next to Has Exit Time 400 00:22:13.589 --> 00:22:17.806 After that, if Trigger is activated 401 00:22:17.806 --> 00:22:19.518 the animation will pass over right away 402 00:22:22.479 --> 00:22:24.558 I will move closer once the Idle animation is about to end 403 00:22:24.558 --> 00:22:28.686 Then you can see that it runs 404 00:22:28.686 --> 00:22:32.046 Now, I will add the attack animation 405 00:22:32.046 --> 00:22:37.418 Drag and attach the Z Attack 406 00:22:37.418 --> 00:22:42.039 And for it to move over from Move to Attack 407 00:22:42.039 --> 00:22:46.758 the Attack Trigger will have to be activated 408 00:22:46.758 --> 00:22:49.712 So a Parameter needs to be added 409 00:22:49.712 --> 00:22:53.948 Press the + button to select Trigger 410 00:22:53.948 --> 00:22:55.598 I will name it Attack 411 00:22:59.129 --> 00:23:00.920 Next, moving from Move to Attack 412 00:23:00.920 --> 00:23:02.938 A transition will be created 413 00:23:02.938 --> 00:23:04.134 Press the right key 414 00:23:04.134 --> 00:23:06.848 Make transition and connect it 415 00:23:06.848 --> 00:23:09.504 Select the particular transition 416 00:23:09.504 --> 00:23:12.554 Uncheck the Has Exit Time 417 00:23:12.554 --> 00:23:15.497 Press + for the condition 418 00:23:15.497 --> 00:23:17.641 Make sure that the Move isn't selected 419 00:23:17.641 --> 00:23:20.121 but instead the Attack is selected 420 00:23:20.121 --> 00:23:22.956 Dropdown and choose Attack 421 00:23:24.847 --> 00:23:28.114 Then, after we finished the Attack 422 00:23:28.114 --> 00:23:30.938 Send it to AttackDelay mode 423 00:23:30.938 --> 00:23:34.274 Then after playing the Attack animation once 424 00:23:34.274 --> 00:23:36.961 Animation for AttackDelay 425 00:23:36.961 --> 00:23:39.029 will need to be executed 426 00:23:39.029 --> 00:23:41.295 Now, the Idle animation 427 00:23:41.295 --> 00:23:46.739 will be set so that it would be executed in AttackDelay condition 428 00:23:46.739 --> 00:23:49.936 One more Z Idle from the project tab 429 00:23:49.936 --> 00:23:52.276 Drag and drop it 430 00:23:52.276 --> 00:23:54.886 Let's change the name of it to AttackDelay 431 00:23:59.629 --> 00:24:02.583 Press the right key from Attack animation node 432 00:24:02.583 --> 00:24:04.632 Make transition and 433 00:24:04.632 --> 00:24:08.379 Connect to AttackDelay 434 00:24:08.379 --> 00:24:11.490 But the Condition won't be added to this 435 00:24:11.490 --> 00:24:11.981 Why? 436 00:24:11.981 --> 00:24:14.272 After the Attack animation is finished 437 00:24:14.272 --> 00:24:16.968 It will just pass over 438 00:24:16.968 --> 00:24:21.871 Then, in the AttackDelay condition 439 00:24:21.871 --> 00:24:24.441 we will wait for the AttackDelay time 440 00:24:24.441 --> 00:24:27.549 depending on the distance with the player, we will decide on 441 00:24:27.549 --> 00:24:32.780 whether we should choose Attack, Move or Idle 442 00:24:32.780 --> 00:24:35.243 So press the right key in AttackDelay 443 00:24:35.243 --> 00:24:36.458 Make transition and 444 00:24:36.458 --> 00:24:38.479 whether we would go back to Attack 445 00:24:38.479 --> 00:24:41.599 Once again, Make transition 446 00:24:41.599 --> 00:24:42.876 whether we would go over to Move 447 00:24:44.817 --> 00:24:47.256 Then press right key again 448 00:24:47.256 --> 00:24:49.296 Make transition 449 00:24:49.296 --> 00:24:53.548 Connect if we should go to Idle 450 00:24:53.548 --> 00:24:54.728 After this animation 451 00:24:54.728 --> 00:24:56.507 whether we should proceed with Attack animation 452 00:24:56.507 --> 00:24:58.117 or Move animation 453 00:24:58.117 --> 00:25:01.730 or Idle animation 454 00:25:01.730 --> 00:25:04.038 is being decided 455 00:25:04.038 --> 00:25:05.638 Like what we started with 456 00:25:05.638 --> 00:25:08.130 It is quite similar to this picture, right? 457 00:25:08.130 --> 00:25:11.185 In a attack delay condition, whether to go with attack 458 00:25:11.185 --> 00:25:15.554 move, or delay 459 00:25:15.554 --> 00:25:18.725 When moving from AttackDelay to Attack 460 00:25:18.725 --> 00:25:20.484 select a transition 461 00:25:20.484 --> 00:25:22.621 uncheck Has Exit Time 462 00:25:22.621 --> 00:25:24.169 Add Condition 463 00:25:24.169 --> 00:25:26.468 It should be Attack, right? 464 00:25:27.983 --> 00:25:30.639 When moving from AttackDelay to Move 465 00:25:30.639 --> 00:25:32.688 After selecting transition 466 00:25:32.688 --> 00:25:35.109 Uncheck Has Exit Time 467 00:25:35.109 --> 00:25:37.250 Press + for the Condition 468 00:25:37.250 --> 00:25:41.809 Set it so that it would pass over when Move activates 469 00:25:41.809 --> 00:25:44.361 Then, moving over to Idle 470 00:25:44.361 --> 00:25:47.526 We should add Condition, but there is no Parameter 471 00:25:47.526 --> 00:25:51.738 So make sure to check if the Parameter tab is set 472 00:25:51.738 --> 00:25:55.271 Press the + button and select the Trigger menu 473 00:25:55.271 --> 00:25:59.974 We will create an Idle Trigger 474 00:25:59.974 --> 00:26:02.005 So from AttackDelay 475 00:26:02.005 --> 00:26:05.917 to Idle animation 476 00:26:05.917 --> 00:26:08.289 Choose transition 477 00:26:08.289 --> 00:26:10.661 Uncheck Has Exit Time 478 00:26:10.661 --> 00:26:13.488 Press the condition + button 479 00:26:13.488 --> 00:26:18.163 Dropdown and choose Idle 480 00:26:18.163 --> 00:26:19.872 Make sure that it is suitable for the situation 481 00:26:19.872 --> 00:26:23.646 and activate Trigger 482 00:26:23.646 --> 00:26:26.508 Come back to the script 483 00:26:26.508 --> 00:26:30.475 The condition that converts for ChangeState 484 00:26:30.475 --> 00:26:32.296 If it is attack, then it would be here, right? 485 00:26:34.300 --> 00:26:37.083 Hey anim, out of the functions that you have 486 00:26:37.083 --> 00:26:40.549 Execute SetTrigger function 487 00:26:40.549 --> 00:26:43.097 Then we should write Attack 488 00:26:46.175 --> 00:26:47.470 Next, if it is in the Move condition 489 00:26:47.470 --> 00:26:50.996 This case will be invoked 490 00:26:50.996 --> 00:26:53.729 The Move animation will be executed 491 00:26:53.729 --> 00:26:56.129 But Idle animation is not there 492 00:26:56.129 --> 00:26:58.659 So we will add one more case 493 00:26:58.659 --> 00:27:01.728 Idle in Case EnemyState 494 00:27:05.339 --> 00:27:08.637 In this case, hey anim, out of the functions you have 495 00:27:08.637 --> 00:27:09.787 I will execute SetTrigger 496 00:27:12.459 --> 00:27:14.670 This means that Idle Trigger will be operated 497 00:27:14.670 --> 00:27:17.019 to allow Idle animation 498 00:27:19.519 --> 00:27:21.216 Look close at the Animator 499 00:27:23.226 --> 00:27:24.296 Play it 500 00:27:26.708 --> 00:27:28.375 It is in an Idle state at first 501 00:27:31.389 --> 00:27:33.990 It will be a Move when I move closer 502 00:27:33.990 --> 00:27:36.518 If it comes closer, it will pass to Attack and AttackDelay 503 00:27:36.518 --> 00:27:38.282 Attack and AttackDelay 504 00:27:38.282 --> 00:27:40.758 Attack and AttackDelay 505 00:27:40.758 --> 00:27:44.102 During the AttackDelay, if I 506 00:27:44.102 --> 00:27:46.567 move further away, it will go with Move 507 00:27:48.567 --> 00:27:51.122 I will move away further, right? 508 00:27:52.439 --> 00:27:54.426 Once again 509 00:27:57.338 --> 00:27:59.288 I will move away completely 510 00:27:59.288 --> 00:28:01.178 Then you can see that it passes to an Idle state 511 00:28:04.297 --> 00:28:07.935 While you proceed with the project 512 00:28:07.935 --> 00:28:11.107 There will be various animations 513 00:28:11.107 --> 00:28:13.438 For now, the animations related to Attack are 514 00:28:13.438 --> 00:28:16.318 This Attack and Attack Delay, right? 515 00:28:16.318 --> 00:28:18.511 For example, this motion called Attack 516 00:28:18.511 --> 00:28:21.488 Let's say there are multiple types other than this 517 00:28:21.488 --> 00:28:24.114 Then depending on the situation 518 00:28:24.114 --> 00:28:27.014 every animations have to be set 519 00:28:27.014 --> 00:28:30.157 Then this page will become very complicated 520 00:28:30.157 --> 00:28:32.170 So in Animator 521 00:28:32.170 --> 00:28:37.156 there is a function called Sub State Machine 522 00:28:37.156 --> 00:28:40.129 If you press the right button of the mouse in this empty space 523 00:28:40.129 --> 00:28:42.306 You can see the menu pop up 524 00:28:42.306 --> 00:28:48.037 There is a menu called Create Sub State Machine 525 00:28:48.037 --> 00:28:49.539 If you press this menu 526 00:28:49.539 --> 00:28:53.468 Another mode in a different shape will be created 527 00:28:53.468 --> 00:28:56.234 Select the node 528 00:28:56.234 --> 00:28:59.998 Let's name it as Attack Process 529 00:29:04.688 --> 00:29:07.633 Then, this Attack and Attack Delay 530 00:29:07.633 --> 00:29:10.335 Drag and select all of it 531 00:29:10.335 --> 00:29:13.519 Press on the left button of the mouse 532 00:29:13.519 --> 00:29:16.739 If you bring it over to the Attack Process 533 00:29:16.739 --> 00:29:20.308 The + icon will be activated 534 00:29:20.308 --> 00:29:23.156 Then if you move the mouse away 535 00:29:23.156 --> 00:29:25.822 These two animations 536 00:29:25.822 --> 00:29:27.737 will move inside the Attack Process 537 00:29:30.889 --> 00:29:35.326 If you double click on the Attack Process 538 00:29:35.326 --> 00:29:37.169 I will organize the information 539 00:29:37.169 --> 00:29:38.967 Like so, what we have put inside 540 00:29:38.967 --> 00:29:42.385 These two nodes go in 541 00:29:42.385 --> 00:29:46.868 and automatically connect other transitions 542 00:29:46.868 --> 00:29:49.727 So in the Move condition 543 00:29:49.727 --> 00:29:51.404 if it is converted to Attack condition 544 00:29:51.404 --> 00:29:54.669 It moves inside to the Attack Process 545 00:29:54.669 --> 00:29:56.842 which leads to Attack being operated first 546 00:29:56.842 --> 00:30:00.608 and then automatically, Attack Delay will be operated 547 00:30:00.608 --> 00:30:03.818 Whether to go back to Attack 548 00:30:03.818 --> 00:30:07.735 or go back to the layer on the top 549 00:30:07.735 --> 00:30:13.048 and whether to go to Move or Idle will be decided 550 00:30:13.048 --> 00:30:15.320 Depending on the operation of the animation 551 00:30:15.320 --> 00:30:17.294 The Animator window will change as well 552 00:30:17.294 --> 00:30:20.308 Let's try it 553 00:30:20.308 --> 00:30:21.436 Press Play 554 00:30:24.149 --> 00:30:26.815 If we head over to the zombie, it will come in Move 555 00:30:26.815 --> 00:30:28.748 If we move to Attack, it comes over 556 00:30:30.599 --> 00:30:32.542 If we move away further 557 00:30:32.542 --> 00:30:35.882 Going back again to the upper layer 558 00:30:35.882 --> 00:30:40.022 which has this Attack Process 559 00:30:40.022 --> 00:30:43.458 We will operate Idle animation 560 00:30:43.458 --> 00:30:47.305 So when you think that animations have increased 561 00:30:47.305 --> 00:30:49.895 and the types of animations are 562 00:30:49.895 --> 00:30:54.578 in a particular condition 563 00:30:54.578 --> 00:30:58.561 Like so, use the Sub State Machine 564 00:30:58.561 --> 00:31:01.605 in order to organize into groups 565 00:31:03.977 --> 00:31:08.798 This time, when the enemy is attacking the player 566 00:31:08.798 --> 00:31:13.789 we are operating the animation 567 00:31:13.789 --> 00:31:17.730 but also executing print attack as well 568 00:31:17.730 --> 00:31:22.325 The timing of when the print called attack is printed 569 00:31:22.325 --> 00:31:25.254 and the timing of the animation that attacks 570 00:31:25.254 --> 00:31:26.258 will be looked at closely 571 00:31:29.089 --> 00:31:35.329 If you take a look, when it is passed over to an attack condition 572 00:31:35.329 --> 00:31:39.718 You can see that this print attack appears 573 00:31:39.718 --> 00:31:43.889 From Move condition to Attack Process 574 00:31:43.889 --> 00:31:48.003 A print called attack appears on the screen 575 00:31:48.003 --> 00:31:53.129 At the same time, this zombie model will be proceeding the animation 576 00:31:53.129 --> 00:31:56.698 It will take the action of swinging the right hand 577 00:31:59.828 --> 00:32:04.886 So when the right hand is about this far 578 00:32:04.886 --> 00:32:07.469 It should be passed over to the attack condition 579 00:32:07.469 --> 00:32:12.223 But it gives a sign of attack, right when it has started 580 00:32:12.223 --> 00:32:15.293 If this happens, in the player's perspective 581 00:32:15.293 --> 00:32:20.017 It seems likes it is being attacked 582 00:32:20.017 --> 00:32:23.836 even when the monster hasn't attacked it properly 583 00:32:23.836 --> 00:32:26.735 So this print called attack 584 00:32:26.735 --> 00:32:29.617 The attacking point 585 00:32:29.617 --> 00:32:33.260 When the hand has come up this far, by swinging its arm 586 00:32:33.260 --> 00:32:38.094 I will change it so that it will be operated at that time 587 00:32:38.094 --> 00:32:40.943 I will create a script in the project window 588 00:32:40.943 --> 00:32:43.094 Select script folder 589 00:32:43.094 --> 00:32:46.243 Press the + button, C# Script 590 00:32:46.243 --> 00:32:49.786 Let's name it HitEvent 591 00:32:53.768 --> 00:32:57.646 Let's attach this script to zombie game object 592 00:32:57.646 --> 00:33:00.376 It shouldn't be attached to Enemy game object 593 00:33:00.376 --> 00:33:03.198 In the zombie game object 594 00:33:03.198 --> 00:33:07.977 I will drag and attach it 595 00:33:07.977 --> 00:33:11.189 Open up HitEvent script 596 00:33:11.189 --> 00:33:14.899 The Update function is unnecessary, so I will erase it 597 00:33:14.899 --> 00:33:22.244 For the global variable, EnemyFSM component 598 00:33:24.769 --> 00:33:25.208 I will create a variable 599 00:33:25.327 --> 00:33:31.537 I will write public EnemyFSM and call it FSM 600 00:33:33.666 --> 00:33:36.602 And then I will create a function 601 00:33:36.602 --> 00:33:45.209 The function that will be invoked at the exact attacking timing 602 00:33:45.209 --> 00:33:53.096 I will make a function called public void PayerHit 603 00:33:53.096 --> 00:33:57.451 Through this function, the attack being 604 00:33:57.451 --> 00:34:00.878 printed from EnemyFSM will be operated 605 00:34:00.878 --> 00:34:03.177 I will create a function 606 00:34:03.177 --> 00:34:05.419 Come down to the bottom 607 00:34:05.419 --> 00:34:09.718 public void AttackAction 608 00:34:14.179 --> 00:34:22.078 I will print the print attack 609 00:34:22.078 --> 00:34:24.821 Then what was in the ChangeState function 610 00:34:24.821 --> 00:34:28.238 This attack print will be eliminated 611 00:34:28.238 --> 00:34:33.159 And come back to HitEvent Script 612 00:34:33.159 --> 00:34:36.807 Hey FSM, out of the function you have 613 00:34:36.807 --> 00:34:42.466 Operate the function called AttackAction 614 00:34:42.466 --> 00:34:44.299 Then PayerHit 615 00:34:44.299 --> 00:34:46.509 What would happen if it is invoked? 616 00:34:46.509 --> 00:34:49.047 The function that EnemyFSM has 617 00:34:51.308 --> 00:34:53.958 the AttackAction function will be executed 618 00:34:53.958 --> 00:34:56.629 The attack will be printed, right? 619 00:34:56.629 --> 00:34:59.620 What is left is to make sure that Payer Hit 620 00:34:59.620 --> 00:35:04.979 is invoked at the exact attack timing 621 00:35:04.979 --> 00:35:07.727 After you come back to the editor 622 00:35:07.727 --> 00:35:11.472 Select the zombie folder from the project window 623 00:35:11.472 --> 00:35:14.198 Then choose the Animations folder 624 00:35:14.198 --> 00:35:17.872 Double click to open the Z Attack file 625 00:35:17.872 --> 00:35:22.288 An animation window will open up like so 626 00:35:22.288 --> 00:35:24.821 And in the Hierarchy 627 00:35:24.821 --> 00:35:27.978 If you select the zombie game object 628 00:35:27.978 --> 00:35:32.576 the player button will be activated like so 629 00:35:32.576 --> 00:35:36.736 And right below, Z idle has been 630 00:35:36.736 --> 00:35:38.929 selected, right? 631 00:35:38.929 --> 00:35:41.074 If we play it 632 00:35:41.074 --> 00:35:44.773 Like so, you can see the zombie in the preview 633 00:35:44.773 --> 00:35:48.379 Executing the Idle animation 634 00:35:48.379 --> 00:35:51.734 And if you select this Z Idle 635 00:35:51.734 --> 00:35:54.268 It will expand the menu 636 00:35:54.268 --> 00:35:56.603 allowing the selection of Z Attack 637 00:35:56.603 --> 00:36:00.108 and the selection of Z Run Inplace 638 00:36:00.108 --> 00:36:02.226 Modify to Z Attack 639 00:36:02.226 --> 00:36:03.670 and if we press play again 640 00:36:03.670 --> 00:36:06.276 We can see the preview of the attacking animation 641 00:36:08.679 --> 00:36:12.885 Or if we select the mouse of the time line 642 00:36:12.885 --> 00:36:16.358 You can see the motion that fits the location 643 00:36:18.516 --> 00:36:21.220 If we lift up its hands 644 00:36:21.220 --> 00:36:23.050 It won't be attacking 645 00:36:23.050 --> 00:36:27.049 but instead, when its hands are reaching forward 646 00:36:27.049 --> 00:36:28.989 It will be attacking 647 00:36:28.989 --> 00:36:34.429 This part means attacking at the right timing 648 00:36:34.429 --> 00:36:35.779 So depending on your desire of timing 649 00:36:35.779 --> 00:36:39.288 You can move it 650 00:36:39.288 --> 00:36:40.963 Below the time line 651 00:36:40.963 --> 00:36:44.600 In this line that says Z Attack 652 00:36:44.600 --> 00:36:47.788 If you press the right key of the mouse 653 00:36:47.788 --> 00:36:51.341 There is a menu called Add Animation Event 654 00:36:51.341 --> 00:36:55.568 If you select that menu 655 00:36:55.568 --> 00:37:01.375 A small icon like so will be added 656 00:37:01.375 --> 00:37:03.903 if you select that icon 657 00:37:03.903 --> 00:37:08.079 It will say that it has been selected, in a blue color 658 00:37:08.079 --> 00:37:12.162 In the Inspector, animation event 659 00:37:12.162 --> 00:37:16.828 and a menu to add the function 660 00:37:16.828 --> 00:37:18.749 Next, No Function Selected 661 00:37:18.749 --> 00:37:20.870 If you click on that part 662 00:37:20.870 --> 00:37:24.010 Like so, inside the HitEvent 663 00:37:24.010 --> 00:37:27.429 The PlayerHit that is inside the method 664 00:37:27.429 --> 00:37:30.548 can be selected 665 00:37:30.548 --> 00:37:34.390 PlayerHit which is inside the method function of Hit Event 666 00:37:34.390 --> 00:37:38.788 You can see that it has been selected 667 00:37:38.788 --> 00:37:41.112 What happens next after the selection? 668 00:37:41.112 --> 00:37:43.978 When the attack animation is being executed 669 00:37:43.978 --> 00:37:45.890 When it is executed like so 670 00:37:45.890 --> 00:37:48.238 When it has come that timing 671 00:37:48.238 --> 00:37:52.724 It plays the role of executing the function 672 00:37:52.724 --> 00:37:56.608 Then, when you have reached forward 673 00:37:56.608 --> 00:37:59.597 A print called attack will be printed 674 00:38:01.778 --> 00:38:04.430 After the selection of zombie game object 675 00:38:04.430 --> 00:38:09.379 FSM isn't set in the HitEvent script 676 00:38:09.379 --> 00:38:13.217 In the parent game object 677 00:38:13.217 --> 00:38:16.659 I will put the EnemyFSM inside 678 00:38:16.659 --> 00:38:21.500 So,after selecting zombie game object 679 00:38:21.500 --> 00:38:24.276 The Enemy game object that is right above 680 00:38:24.276 --> 00:38:26.874 will be dragged and attached 681 00:38:26.874 --> 00:38:29.989 So what the Enemy game object has 682 00:38:29.989 --> 00:38:34.098 this EnemyFSM component will be put inside 683 00:38:37.179 --> 00:38:38.167 Move closer 684 00:38:41.219 --> 00:38:46.246 You can see that it is able to attack at the exact timing 685 00:38:46.246 --> 00:38:49.416 When the player has attacked the enemy 686 00:38:49.416 --> 00:38:51.026 It will be in a Damaged condition 687 00:38:51.026 --> 00:38:53.856 The animation that occurs during that timing 688 00:38:53.856 --> 00:38:57.858 will be what we create next 689 00:38:57.858 --> 00:38:59.489 The damage animation 690 00:38:59.489 --> 00:39:03.349 does not exist in the Asset that we have downloaded so 691 00:39:03.349 --> 00:39:07.298 We will download it separately 692 00:39:07.298 --> 00:39:11.193 If you open up the URL on the screen 693 00:39:11.193 --> 00:39:14.308 There will be a Zombiehitfbx file 694 00:39:14.308 --> 00:39:16.512 Press the key on the right to download 695 00:39:16.512 --> 00:39:19.639 that file 696 00:39:19.639 --> 00:39:21.714 If it has been downloaded 697 00:39:21.714 --> 00:39:24.768 Select and drag the file 698 00:39:24.768 --> 00:39:27.154 In the project window, in the zombie folder 699 00:39:27.154 --> 00:39:30.808 Move it inside the Animations folder 700 00:39:30.808 --> 00:39:36.338 And select the Zombiehitfbx file that has been added 701 00:39:36.338 --> 00:39:39.899 If you look at the Inspector window 702 00:39:39.899 --> 00:39:41.648 There are four tabs 703 00:39:41.648 --> 00:39:44.587 Select Rig from over here 704 00:39:44.587 --> 00:39:49.399 And change the animation type to Humanoid 705 00:39:49.399 --> 00:39:53.894 And select Apply 706 00:39:53.894 --> 00:39:57.883 And if you expand this zombie hit 707 00:39:57.883 --> 00:40:01.859 There is an animation file that is shaped in a triangle 708 00:40:01.859 --> 00:40:04.119 If you select that file 709 00:40:04.119 --> 00:40:07.129 and copy it by pressing Ctrl+D 710 00:40:07.129 --> 00:40:10.323 Like the animation files on the top 711 00:40:10.323 --> 00:40:12.328 It will come out 712 00:40:12.328 --> 00:40:13.508 I will press Ctrl+D 713 00:40:15.390 --> 00:40:17.123 Then it comes up like so, right? 714 00:40:17.123 --> 00:40:18.987 I will change the name to 715 00:40:18.987 --> 00:40:21.867 z_Damaged 716 00:40:24.219 --> 00:40:29.324 I will drag this file and bring it over to the Animator window 717 00:40:29.324 --> 00:40:31.746 I will change the name of it to Damaged 718 00:40:34.739 --> 00:40:36.976 This damage animation 719 00:40:36.976 --> 00:40:40.539 needs to be executed in any condition 720 00:40:40.539 --> 00:40:42.699 So if you look at the Animator window 721 00:40:42.699 --> 00:40:45.535 There is a node called Any State 722 00:40:45.535 --> 00:40:47.862 What this node is 723 00:40:47.862 --> 00:40:50.555 This model operates Idle or Move 724 00:40:50.555 --> 00:40:53.808 It continues to operate other animation 725 00:40:53.808 --> 00:40:55.616 And if the condition connected to this Any State 726 00:40:55.616 --> 00:40:58.515 is satisfied 727 00:40:58.515 --> 00:41:01.242 It allows the animation to be 728 00:41:01.242 --> 00:41:05.308 operated right away 729 00:41:05.308 --> 00:41:07.665 So this Damaged animation 730 00:41:07.665 --> 00:41:11.419 should be connected in the Any State 731 00:41:11.419 --> 00:41:13.597 So in the Any State 732 00:41:13.597 --> 00:41:16.735 Click the right key of the mouse in order to Make Transition 733 00:41:16.735 --> 00:41:19.577 Connect it to Damaged 734 00:41:19.577 --> 00:41:22.173 And a Trigger should be created 735 00:41:22.173 --> 00:41:24.618 which allows the transition to be operated 736 00:41:24.618 --> 00:41:26.605 The Parameters tab of Animator 737 00:41:26.605 --> 00:41:30.178 Check if it has been selected and press the + button 738 00:41:30.178 --> 00:41:32.011 To add Trigger 739 00:41:32.011 --> 00:41:34.448 Let's name this Damaged 740 00:41:36.785 --> 00:41:39.249 After selecting this transition 741 00:41:39.249 --> 00:41:42.404 I will add Condition on the right 742 00:41:42.404 --> 00:41:46.590 And choose Damaged 743 00:41:46.590 --> 00:41:50.084 To make this Trigger occur 744 00:41:50.084 --> 00:41:54.508 Come over to ChangeState function of EnemyFSM 745 00:41:54.508 --> 00:41:57.679 If it comes in a Damaged condition 746 00:41:57.679 --> 00:42:01.169 we should operate the Trigger 747 00:42:01.169 --> 00:42:04.001 I will add one more below the Move condition 748 00:42:04.001 --> 00:42:09.567 If it is in a Damaged condition in the Case Enemy State 749 00:42:12.528 --> 00:42:14.546 Let's say hey, anim 750 00:42:14.546 --> 00:42:18.436 using the Set Trigger function that you have 751 00:42:18.436 --> 00:42:21.338 We will operate the Damaged Trigger 752 00:42:24.367 --> 00:42:25.396 We will play this 753 00:42:28.008 --> 00:42:30.679 Press the left button of the mouse to attack 754 00:42:30.679 --> 00:42:32.723 So then, Damaged 755 00:42:32.723 --> 00:42:35.538 animation will be executed 756 00:42:35.538 --> 00:42:38.246 But it stops after being finished, right? 757 00:42:40.088 --> 00:42:41.933 After the Damaged action 758 00:42:41.933 --> 00:42:45.788 and then if the damage delay time is over 759 00:42:45.788 --> 00:42:47.922 We have to move to Idle or Move 760 00:42:47.922 --> 00:42:50.907 or proceed the attack 761 00:42:50.907 --> 00:42:53.295 It is being operated according to the code 762 00:42:53.295 --> 00:42:56.028 but in the animation condition 763 00:42:56.028 --> 00:42:59.389 There isn't a transition path to proceed 764 00:42:59.389 --> 00:43:03.527 When we drew this diagram 765 00:43:03.527 --> 00:43:05.962 After it had come to the damaged condition 766 00:43:05.962 --> 00:43:09.558 whether to proceed with delay, move, or attack 767 00:43:09.558 --> 00:43:11.749 had to be drawn 768 00:43:11.749 --> 00:43:15.108 Like so, I will set it so that 769 00:43:15.108 --> 00:43:18.219 this animation can be a transition 770 00:43:18.219 --> 00:43:21.006 In the Damaged animation node 771 00:43:21.006 --> 00:43:22.818 Press the right button 772 00:43:22.818 --> 00:43:24.859 After the Make Transition 773 00:43:24.859 --> 00:43:27.218 connect to Idle 774 00:43:27.218 --> 00:43:29.435 Select transition 775 00:43:29.435 --> 00:43:31.611 Uncheck the Has Exit Time and 776 00:43:31.611 --> 00:43:35.288 Add through the Condition + button 777 00:43:35.288 --> 00:43:36.945 This needs to be the Idle 778 00:43:36.945 --> 00:43:39.466 Make sure to change it to Idle 779 00:43:39.466 --> 00:43:42.835 Press the right key in Damaged node 780 00:43:42.835 --> 00:43:46.139 and connect to Make Transition Move 781 00:43:46.139 --> 00:43:48.814 After selecting the transition that has been added 782 00:43:48.814 --> 00:43:51.852 Uncheck the Has Exit Time 783 00:43:51.852 --> 00:43:56.608 Make sure to check if it has been set to Condition Move 784 00:43:56.608 --> 00:44:00.091 Lastly, in the Damaged node 785 00:44:00.091 --> 00:44:01.685 Press the right button 786 00:44:01.685 --> 00:44:03.410 and Make Transition 787 00:44:03.410 --> 00:44:06.290 to connect to Attack Process 788 00:44:06.290 --> 00:44:09.284 Over here, to the State list 789 00:44:09.284 --> 00:44:10.867 If you bring the mouse over 790 00:44:10.867 --> 00:44:13.129 There is an AttackDelay and Attack 791 00:44:13.129 --> 00:44:14.999 Attack needs to come first for us, right? 792 00:44:14.999 --> 00:44:17.364 So we will select the Attack 793 00:44:17.364 --> 00:44:20.787 Next, select the transition that has been added 794 00:44:20.787 --> 00:44:22.909 Uncheck the Has Exit Time 795 00:44:22.909 --> 00:44:26.884 And then add one more Condition 796 00:44:26.884 --> 00:44:30.177 Let's change the Condition to Attack 797 00:44:32.207 --> 00:44:34.633 I will take a look 798 00:44:34.633 --> 00:44:36.681 If it attacks 799 00:44:36.681 --> 00:44:39.362 Operates the Damaged animation and moves over to Idle 800 00:44:39.362 --> 00:44:42.489 Operating the Damaged animation again and moving over to the Idle 801 00:44:42.489 --> 00:44:44.147 You can see it, right? 802 00:44:44.147 --> 00:44:46.688 Then I will make it approach and follow 803 00:44:46.688 --> 00:44:49.018 If it attacks after the Move 804 00:44:49.018 --> 00:44:51.537 It stops, and then follows 805 00:44:51.537 --> 00:44:53.901 Stops, and then follow again 806 00:44:53.901 --> 00:44:56.926 If it attacks in the middle of an attack 807 00:44:56.926 --> 00:44:59.580 It goes "AHH!" and then attacks 808 00:44:59.580 --> 00:45:02.359 "AHH!" and then attacks again 809 00:45:02.359 --> 00:45:05.444 We can check its movement 810 00:45:05.444 --> 00:45:08.629 Next, when it is in a dead condition 811 00:45:08.629 --> 00:45:12.820 we will set the animation that will be operated 812 00:45:12.820 --> 00:45:15.040 Out of the animation list 813 00:45:15.040 --> 00:45:17.339 There is Z Falling Back 814 00:45:17.339 --> 00:45:19.509 and Z Falling Forward 815 00:45:19.509 --> 00:45:21.943 It wouldn't matter to use either of them 816 00:45:21.943 --> 00:45:25.258 I will use Forward 817 00:45:25.258 --> 00:45:29.630 If you look on the top, there is a tab that is called Base Layer 818 00:45:29.630 --> 00:45:31.614 If you press this tab 819 00:45:31.614 --> 00:45:34.528 It moves over to the upper layer 820 00:45:34.528 --> 00:45:36.361 Change it like so 821 00:45:36.361 --> 00:45:40.611 I will drag Z Falling Forward to insert it 822 00:45:40.611 --> 00:45:44.959 I will change the name to Die 823 00:45:44.959 --> 00:45:46.693 Same for the Die 824 00:45:46.693 --> 00:45:49.289 No matter what condition it is in 825 00:45:49.289 --> 00:45:51.388 It needs to be operated 826 00:45:51.388 --> 00:45:53.763 In order to make it operate from Any State 827 00:45:53.763 --> 00:45:57.278 I will create the transition 828 00:45:57.278 --> 00:46:00.397 Press the right button from Any State node 829 00:46:00.397 --> 00:46:02.986 Select Make Transition 830 00:46:02.986 --> 00:46:05.438 and connect to Die 831 00:46:05.438 --> 00:46:09.029 Making sure that the transition can be operated 832 00:46:09.029 --> 00:46:12.127 I will add a Trigger Parameter 833 00:46:12.127 --> 00:46:15.523 Press the + button, select Trigger 834 00:46:15.523 --> 00:46:19.748 Let's add while naming it Die 835 00:46:19.748 --> 00:46:23.168 And select the transition 836 00:46:23.168 --> 00:46:24.474 I will add a Condition 837 00:46:24.474 --> 00:46:28.000 Press the + button to add and modify 838 00:46:28.000 --> 00:46:28.500 To what? 839 00:46:28.500 --> 00:46:29.374 Modify to Die 840 00:46:30.938 --> 00:46:33.303 So in order for the Trigger to be operated 841 00:46:33.303 --> 00:46:36.589 we have to write down the code 842 00:46:36.589 --> 00:46:39.031 Come over to EnemyFSM script 843 00:46:39.031 --> 00:46:43.312 When it is in the Die condition from ChangeState 844 00:46:43.312 --> 00:46:45.820 It is destructing the game object after a second 845 00:46:45.820 --> 00:46:49.138 We can make this as an animation then 846 00:46:49.138 --> 00:46:50.953 Hey anim, out of what you have 847 00:46:50.953 --> 00:46:53.609 Utilize the SetTrigger function 848 00:46:53.609 --> 00:46:56.595 to operate Die Trigger 849 00:46:58.699 --> 00:47:03.032 Save it and come back to the editor 850 00:47:03.032 --> 00:47:06.235 Play it and let's quickly attack 851 00:47:12.473 --> 00:47:15.094 If it is attacking 852 00:47:15.094 --> 00:47:18.089 it will be in a Die mode 853 00:47:18.089 --> 00:47:21.008 You can see that it disappears after collapsing 854 00:47:21.008 --> 00:47:22.733 But if you want the collapsed condition 855 00:47:22.733 --> 00:47:26.046 to continue longer 856 00:47:26.046 --> 00:47:28.558 Do not destruct it after a second 857 00:47:28.558 --> 00:47:31.889 Set it destruct after 3 seconds 858 00:47:31.889 --> 00:47:35.538 to see the character collapse a little longer 859 00:47:35.538 --> 00:47:36.866 Let's play once again 860 00:47:40.367 --> 00:47:45.243 Attack quickly. It will die in one, two, three, four, five times 861 00:47:45.243 --> 00:47:48.976 When it dies, the character collapsing 862 00:47:48.976 --> 00:47:51.169 needs to be checked for a bit 863 00:47:51.169 --> 00:47:52.749 and then you can see it disappear 864 00:47:55.550 --> 00:47:59.076 Like so, depending on any condition of the Enemy 865 00:47:59.076 --> 00:48:01.575 We have implemented it so that 866 00:48:01.575 --> 00:48:03.919 the animation can be executed 867 00:48:03.919 --> 00:48:07.425 So let's do an overview of what we learned 868 00:48:07.805 --> 00:48:10.205 Overview Application of enemy model Asset Store Window Asset Store Search online Hide the basic shapes by deactivating the Mesh Renderer component of the Enemy 869 00:48:10.205 --> 00:48:12.647 Adjust the transform position value The exterior can be modified through the Asset store or art director after being implemented at the beginning of the project development 870 00:48:12.656 --> 00:48:13.470 Enemy animation Idle animation Create Idle node through clicking and dragging Z Idle file to the Animator window 871 00:48:13.470 --> 00:48:14.462 The first file of the Animator tab is connected to the Entry node automatically The Animator needs to be in the Controller attribute of the object to operate 872 00:48:14.462 --> 00:48:15.365 Move animation Create Move node by clicking and dragging the Z Run Inplace file in the Animator tab 873 00:48:15.365 --> 00:48:16.074 Click the right key of the mouse on the Idle node and click Transition to connect the Move node Create Move parameter by clicking Animator Parameter + Trigger 874 00:48:16.074 --> 00:48:16.724 Uncheck Has Exit Time of Transition, add Move to the condition and write Trigger activating code Animator #4 Animater anim; Bring over Animator component 875 00:48:16.724 --> 00:48:17.409 anmi=GetComponentInChildren Animator; Write on switch condition of ChangeState function anim. SetTrigger Move; 876 00:48:17.419 --> 00:48:18.114 Attack animation Click and drag Z Attack file on the Animator tab to create Attack node Click and drag Z Idle file to create AttackDel node 877 00:48:18.114 --> 00:48:18.790 After connecting from Attack to AttackDelay, do not add to the condition Connect transition from AttackDelay node to Attack, Move, Idle node 878 00:48:18.790 --> 00:48:19.446 Write trigger operating code depending on the situation When a certain animation type increases in a situation, use Sub-State Machine function Enemy animation 879 00:48:19.446 --> 00:48:20.062 Attack animation Click and drag Z Attack file to the animator window to create Attack node Click and drag Z Idle to create AttackDelay node 880 00:48:20.062 --> 00:48:20.702 Connect transition from AttackDelay node to Attack, Move, Idle node Write Trigger operating code depending on the situation 881 00:48:20.702 --> 00:48:21.285 Utilize Sub State Machine function when a certain animation type increases in a condition Damaged animation Z Damaged file into Animator window 882 00:48:21.285 --> 00:48:21.835 Click and drag to create Damaged node Connect to Any State node since it operates regardless of the Enemy's condition 883 00:48:21.835 --> 00:48:22.359 Connect transition from Damaged node to Idle, Move, Attack Process node Write trigger operating code depending on the situation 884 00:48:22.359 --> 00:48:25.111 Connect transition from Damaged node to Idle, Move, Attack Process node Write trigger operating code depending on the situation 885 00:48:25.111 --> 00:48:27.765 Write trigger operating code after connecting to the Any state node Adjust the time of Enemy being passed out by modifying the time variable of the Destroy function