[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:02.33,0:00:04.17,Default,,0000,0000,0000,,In this video we're going to setup our Dialogue: 0,0:00:04.17,0:00:06.17,Default,,0000,0000,0000,,player animator controller so that Dialogue: 0,0:00:06.17,0:00:08.17,Default,,0000,0000,0000,,we can control what animation Dialogue: 0,0:00:08.17,0:00:11.17,Default,,0000,0000,0000,,is playing via a script. Dialogue: 0,0:00:11.17,0:00:13.17,Default,,0000,0000,0000,,The first thing that we're going to do is to add Dialogue: 0,0:00:13.17,0:00:15.74,Default,,0000,0000,0000,,the player prefab back to the hierarchy. Dialogue: 0,0:00:16.22,0:00:18.22,Default,,0000,0000,0000,,Let's go to Prefabs Dialogue: 0,0:00:20.01,0:00:23.76,Default,,0000,0000,0000,,select the player and drag to the hierarchy. Dialogue: 0,0:00:25.07,0:00:29.51,Default,,0000,0000,0000,,Next we're going to open our player animator controller. Dialogue: 0,0:00:29.51,0:00:31.51,Default,,0000,0000,0000,,Let's go to Animations Dialogue: 0,0:00:32.99,0:00:34.99,Default,,0000,0000,0000,,Animator Controllers Dialogue: 0,0:00:35.92,0:00:37.92,Default,,0000,0000,0000,,and double click Player. Dialogue: 0,0:00:39.28,0:00:41.68,Default,,0000,0000,0000,,Here we have the animations that we created Dialogue: 0,0:00:41.68,0:00:43.98,Default,,0000,0000,0000,,earlier which have been added to the animator Dialogue: 0,0:00:43.98,0:00:45.83,Default,,0000,0000,0000,,controller has states. Dialogue: 0,0:00:45.83,0:00:47.83,Default,,0000,0000,0000,,Let's lay these out so that we can see them a little more Dialogue: 0,0:00:47.83,0:00:49.83,Default,,0000,0000,0000,,clearly and we'll move the PlayerIdle up, Dialogue: 0,0:00:50.82,0:00:52.82,Default,,0000,0000,0000,,the PlayerChop will be over here and Dialogue: 0,0:00:52.82,0:00:54.82,Default,,0000,0000,0000,,the PlayerHit will be over here. Dialogue: 0,0:00:55.12,0:00:59.10,Default,,0000,0000,0000,,The PlayerIdle is orange because it's the default state. Dialogue: 0,0:00:59.10,0:01:01.10,Default,,0000,0000,0000,,So when the game starts playing Dialogue: 0,0:01:01.10,0:01:03.88,Default,,0000,0000,0000,,the player's idle animation is going to play. Dialogue: 0,0:01:03.88,0:01:05.88,Default,,0000,0000,0000,,What we're going to do is setup the transitions Dialogue: 0,0:01:05.88,0:01:08.90,Default,,0000,0000,0000,,when the PlayerIdle animation will stop playing and will Dialogue: 0,0:01:08.90,0:01:10.90,Default,,0000,0000,0000,,transition to either the Chop animation, Dialogue: 0,0:01:10.90,0:01:12.90,Default,,0000,0000,0000,,when the player attacks a wall, Dialogue: 0,0:01:12.90,0:01:14.90,Default,,0000,0000,0000,,or to the Hit animation when the player Dialogue: 0,0:01:14.90,0:01:16.90,Default,,0000,0000,0000,,is attacked by an enemy. Dialogue: 0,0:01:17.18,0:01:19.18,Default,,0000,0000,0000,,The first thing that we're going to want to do is setup Dialogue: 0,0:01:19.18,0:01:21.18,Default,,0000,0000,0000,,some parameters which are going to Dialogue: 0,0:01:21.18,0:01:23.18,Default,,0000,0000,0000,,be what we're going to use to trigger Dialogue: 0,0:01:23.18,0:01:26.09,Default,,0000,0000,0000,,those animations from our scripts. Dialogue: 0,0:01:26.38,0:01:28.38,Default,,0000,0000,0000,,You may need to click the Parameters button to Dialogue: 0,0:01:28.38,0:01:30.06,Default,,0000,0000,0000,,make the parameters visible, Dialogue: 0,0:01:30.06,0:01:32.28,Default,,0000,0000,0000,,and then we'll hit the + button Dialogue: 0,0:01:32.28,0:01:35.18,Default,,0000,0000,0000,,and add a parameter of the type trigger. Dialogue: 0,0:01:35.87,0:01:38.27,Default,,0000,0000,0000,,This first one is going to be called playerChop. Dialogue: 0,0:01:38.68,0:01:42.08,Default,,0000,0000,0000,,A trigger is like a boolean except it will Dialogue: 0,0:01:42.08,0:01:45.89,Default,,0000,0000,0000,,immediately be reset after it's used in a transition. Dialogue: 0,0:01:45.89,0:01:48.50,Default,,0000,0000,0000,,So it's a boolean that's going to remain true Dialogue: 0,0:01:48.50,0:01:50.50,Default,,0000,0000,0000,,for the frame in which it's called Dialogue: 0,0:01:50.50,0:01:52.50,Default,,0000,0000,0000,,and then become false again. Dialogue: 0,0:01:53.37,0:01:56.10,Default,,0000,0000,0000,,We're going to create another one called playerHit. Dialogue: 0,0:01:56.40,0:01:59.44,Default,,0000,0000,0000,,Next we want to create some transitions between our states. Dialogue: 0,0:01:59.44,0:02:01.21,Default,,0000,0000,0000,,Let's right click PlayerIdle, Dialogue: 0,0:02:01.75,0:02:03.75,Default,,0000,0000,0000,,select Make Transition, Dialogue: 0,0:02:04.09,0:02:07.00,Default,,0000,0000,0000,,and drag to our PlayerChop state. Dialogue: 0,0:02:08.41,0:02:11.14,Default,,0000,0000,0000,,We're then going to right click on PlayerChop Dialogue: 0,0:02:11.14,0:02:13.14,Default,,0000,0000,0000,,and make a transition back from Dialogue: 0,0:02:13.14,0:02:16.04,Default,,0000,0000,0000,,PlayerChop to PlayerIdle. Dialogue: 0,0:02:16.04,0:02:18.04,Default,,0000,0000,0000,,This means that PlayerIdle can transition Dialogue: 0,0:02:18.04,0:02:20.78,Default,,0000,0000,0000,,to PlayerChop and PlayerChop Dialogue: 0,0:02:20.78,0:02:24.03,Default,,0000,0000,0000,,can then transition back to PlayerIdle. Dialogue: 0,0:02:24.03,0:02:26.42,Default,,0000,0000,0000,,We'll click on the transition from PlayerIdle to Dialogue: 0,0:02:26.42,0:02:29.10,Default,,0000,0000,0000,,PlayerChop to make it visible in the inspector. Dialogue: 0,0:02:29.49,0:02:33.40,Default,,0000,0000,0000,,The transition from PlayerIdle to PlayerChop Dialogue: 0,0:02:33.40,0:02:36.40,Default,,0000,0000,0000,,is not going to have an exit time. Dialogue: 0,0:02:36.40,0:02:38.89,Default,,0000,0000,0000,,We're going to uncheck Has Exit Time. Dialogue: 0,0:02:38.89,0:02:41.40,Default,,0000,0000,0000,,What this means is that we're not going to wait Dialogue: 0,0:02:41.40,0:02:43.40,Default,,0000,0000,0000,,for the PlayerIdle animation to finish Dialogue: 0,0:02:43.40,0:02:47.29,Default,,0000,0000,0000,,or to reach any certain point before we can Dialogue: 0,0:02:47.29,0:02:48.81,Default,,0000,0000,0000,,transition to PlayerChop. Dialogue: 0,0:02:48.81,0:02:50.81,Default,,0000,0000,0000,,We're going to want the transition to happen Dialogue: 0,0:02:50.81,0:02:54.61,Default,,0000,0000,0000,,abruptly from PlayerIdle to PlayerChop Dialogue: 0,0:02:54.61,0:02:58.02,Default,,0000,0000,0000,,regardless of where we are in the Idle animation. Dialogue: 0,0:02:58.02,0:03:00.02,Default,,0000,0000,0000,,We're also going to open the settings and Dialogue: 0,0:03:00.02,0:03:03.20,Default,,0000,0000,0000,,set the transition duration to 0. Dialogue: 0,0:03:03.65,0:03:05.65,Default,,0000,0000,0000,,We're going to use a transition duration of 0 Dialogue: 0,0:03:05.65,0:03:08.90,Default,,0000,0000,0000,,when we're working with sprite-based animation. Dialogue: 0,0:03:08.90,0:03:10.90,Default,,0000,0000,0000,,When we're working with 3D animation Dialogue: 0,0:03:10.90,0:03:12.90,Default,,0000,0000,0000,,it's common that we may want to blend Dialogue: 0,0:03:12.90,0:03:15.06,Default,,0000,0000,0000,,between animation states Dialogue: 0,0:03:15.06,0:03:17.98,Default,,0000,0000,0000,,but with sprite-based animation that's not possible Dialogue: 0,0:03:17.98,0:03:20.33,Default,,0000,0000,0000,,so we're going to want to immediately transition Dialogue: 0,0:03:20.33,0:03:22.33,Default,,0000,0000,0000,,from one state to another. Dialogue: 0,0:03:23.14,0:03:25.14,Default,,0000,0000,0000,,Next we're going to determine what is going Dialogue: 0,0:03:25.14,0:03:27.14,Default,,0000,0000,0000,,to cause this transition to happen. Dialogue: 0,0:03:27.14,0:03:29.14,Default,,0000,0000,0000,,In our list of conditions here we're going to click Dialogue: 0,0:03:29.14,0:03:31.98,Default,,0000,0000,0000,,the + button to add a new condition Dialogue: 0,0:03:31.98,0:03:33.98,Default,,0000,0000,0000,,which will determine when the transition Dialogue: 0,0:03:33.98,0:03:35.98,Default,,0000,0000,0000,,will be made. Dialogue: 0,0:03:37.50,0:03:40.38,Default,,0000,0000,0000,,A list of conditions will appear here, Dialogue: 0,0:03:40.38,0:03:42.38,Default,,0000,0000,0000,,in this case PlayerChop, which is the Dialogue: 0,0:03:42.38,0:03:44.76,Default,,0000,0000,0000,,default is actually the condition that we want. Dialogue: 0,0:03:44.76,0:03:47.60,Default,,0000,0000,0000,,If we wanted to change it we could choose from the list Dialogue: 0,0:03:47.60,0:03:50.50,Default,,0000,0000,0000,,and choose either PlayerChop or PlayerHit. Dialogue: 0,0:03:50.50,0:03:52.50,Default,,0000,0000,0000,,Now when the PlayerChop trigger is Dialogue: 0,0:03:52.50,0:03:54.50,Default,,0000,0000,0000,,set from our player script we'll Dialogue: 0,0:03:54.50,0:03:57.96,Default,,0000,0000,0000,,transition from PlayerIdle to PlayerChop. Dialogue: 0,0:03:58.81,0:04:01.65,Default,,0000,0000,0000,,For our transition from PlayerChop Dialogue: 0,0:04:01.65,0:04:05.70,Default,,0000,0000,0000,,back to PlayerIdle here we're going to keep Dialogue: 0,0:04:05.70,0:04:07.70,Default,,0000,0000,0000,,Has Exit Time active but we're going Dialogue: 0,0:04:07.70,0:04:10.61,Default,,0000,0000,0000,,to set it to 1, meaning that the PlayerChop Dialogue: 0,0:04:10.61,0:04:12.61,Default,,0000,0000,0000,,animation is going to need to be completely Dialogue: 0,0:04:12.61,0:04:15.37,Default,,0000,0000,0000,,finished before we're going to transition Dialogue: 0,0:04:15.37,0:04:17.20,Default,,0000,0000,0000,,back to PlayerIdle. Dialogue: 0,0:04:17.20,0:04:20.92,Default,,0000,0000,0000,,We're also going to set the transition duration here to 0. Dialogue: 0,0:04:22.36,0:04:24.36,Default,,0000,0000,0000,,Because we set Has Exit Time Dialogue: 0,0:04:24.36,0:04:26.36,Default,,0000,0000,0000,,to true from PlayerChop Dialogue: 0,0:04:26.36,0:04:28.36,Default,,0000,0000,0000,,to PlayerIdle we're not going to Dialogue: 0,0:04:28.36,0:04:30.36,Default,,0000,0000,0000,,need any additional conditions, Dialogue: 0,0:04:30.36,0:04:32.36,Default,,0000,0000,0000,,the transition will be made Dialogue: 0,0:04:32.36,0:04:34.36,Default,,0000,0000,0000,,when the exit time is reached. Dialogue: 0,0:04:34.59,0:04:37.37,Default,,0000,0000,0000,,Let's setup the same things for PlayerHit. Dialogue: 0,0:04:38.73,0:04:40.36,Default,,0000,0000,0000,,We'll select PlayerIdle, Dialogue: 0,0:04:40.95,0:04:42.95,Default,,0000,0000,0000,,choose Make Transition, Dialogue: 0,0:04:42.95,0:04:44.95,Default,,0000,0000,0000,,and drag to PlayerHit. Dialogue: 0,0:04:46.46,0:04:49.32,Default,,0000,0000,0000,,We'll click on PlayerHit, right click, Dialogue: 0,0:04:49.32,0:04:51.32,Default,,0000,0000,0000,,choose Make Transition, Dialogue: 0,0:04:52.53,0:04:55.31,Default,,0000,0000,0000,,and transition back to PlayerIdle. Dialogue: 0,0:04:57.35,0:04:59.92,Default,,0000,0000,0000,,We'll highlight the transition from PlayerIdle Dialogue: 0,0:04:59.92,0:05:02.84,Default,,0000,0000,0000,,to PlayerHit, and here we're going to set Dialogue: 0,0:05:02.84,0:05:05.36,Default,,0000,0000,0000,,Has Exit Time to false Dialogue: 0,0:05:05.36,0:05:07.36,Default,,0000,0000,0000,,because we want to interrupt the Dialogue: 0,0:05:07.36,0:05:10.96,Default,,0000,0000,0000,,PlayerIdle animation whenever the player is hit. Dialogue: 0,0:05:10.96,0:05:14.52,Default,,0000,0000,0000,,And we're going to set our transition duration again to 0. Dialogue: 0,0:05:16.02,0:05:19.00,Default,,0000,0000,0000,,In our list of conditions we're going to hit the + button, Dialogue: 0,0:05:20.53,0:05:24.23,Default,,0000,0000,0000,,and select PlayerHit from the drop down. Dialogue: 0,0:05:24.96,0:05:27.93,Default,,0000,0000,0000,,For our transition back to PlayerIdle. Dialogue: 0,0:05:28.93,0:05:30.93,Default,,0000,0000,0000,,We're going to use Has Exit Time because Dialogue: 0,0:05:30.93,0:05:33.22,Default,,0000,0000,0000,,we want the animation to finish playing Dialogue: 0,0:05:33.22,0:05:35.64,Default,,0000,0000,0000,,setting Exit Time to 1 because we want it to Dialogue: 0,0:05:35.64,0:05:38.18,Default,,0000,0000,0000,,transition at the end of the animation, Dialogue: 0,0:05:38.18,0:05:41.10,Default,,0000,0000,0000,,and we're going to set the transition duration to 0. Dialogue: 0,0:05:41.92,0:05:44.75,Default,,0000,0000,0000,,Before we move on we're going to give this a quick test. Dialogue: 0,0:05:44.75,0:05:47.26,Default,,0000,0000,0000,,Let's temporarily dock the animator window Dialogue: 0,0:05:47.26,0:05:49.26,Default,,0000,0000,0000,,down here on the bottom of the screen. Dialogue: 0,0:05:50.37,0:05:52.37,Default,,0000,0000,0000,,Play our game, and what we'll do Dialogue: 0,0:05:52.37,0:05:54.37,Default,,0000,0000,0000,,is we're going to manually fire the Dialogue: 0,0:05:54.37,0:05:56.37,Default,,0000,0000,0000,,triggers and see what happens. Dialogue: 0,0:05:57.03,0:05:59.03,Default,,0000,0000,0000,,First we'll try PlayerChop. Dialogue: 0,0:05:59.85,0:06:01.85,Default,,0000,0000,0000,,And then we'll try PlayerHit. Dialogue: 0,0:06:03.45,0:06:05.45,Default,,0000,0000,0000,,Excellent, so we can see that those are working. Dialogue: 0,0:06:06.18,0:06:09.24,Default,,0000,0000,0000,,Now that we've got our player animator controller working Dialogue: 0,0:06:09.24,0:06:11.24,Default,,0000,0000,0000,,we're going to move on in the next video Dialogue: 0,0:06:11.24,0:06:13.24,Default,,0000,0000,0000,,to writing the player script.