Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So in the last video we covered importing our game character into Unity. So now let's look at some ways so that we can add interaction to our game character, and basically the way we do that in Unity is through scripts. So I am going to go ahead and import some scripts into Unity. These are scripts that come preinstalled with Unity. So this is part of the standard assets package that you should have with your install of Unity. So I am just going to go up to Assets > Import Package and I want to import this Character Controller package. So I just want to leave all these selected.
Just go ahead and click Import. Okay and then when I look in my Project folder, we should see this Standard Assets folder and I can expand that down. And there is a couple prefabricated game characters in here that we can play with too, if you would like. But what I want to look forward down here is this Sources, Scripts folder. This has a couple of pre-made scripts that are going to work to allow us to make our character interactive, so it can move around and respond to user input.
So we'll be going to looking at this ThirdPersonController script in this video. And if I click on that I can get a preview of the actual text. Now there are many ways in Unity to make a script that acts as a Character controller. So you can even write your own, a lot of people do it. Unfortunately, we don't really have the time in this course to go over the fundamentals of scripting and all the things you need to know for scripting Unity. But just be aware that there are a lot of different ways to set up a script that does a similar thing, and if you are interested, I would recommend checking out some of the Unity scripting tutorials.
Okay, so we will just make a couple of adjustments to our character in the hierarchy. The script that we are going to be using is actually expecting a model that scaled much smaller. So I am just going to adjust the Scale in my character's Transform component. And I am going to change it from 1 to 0. 01, so we are just going to temporarily make it a lot smaller and that's going to actually just be easier than adjusting the script itself. So I have got my character highlighted in the hierarchy and let's just go back to the Scene view. I am just going to hit F to automatically zoom-in on that character.
Right now, my character is the only thing in the scene. I actually need to give him sort of a floor to walk on. Otherwise, once we attach a Character Controller script, this character will actually have gravity attached to it, so it will just keep falling into space. So let's go ahead and create a GameObject, and I will just make a Plane. I'll just bring that down a little bit, and maybe in the plane's Transform Scale component, I am just going to make that a little bit bigger.
So that will at least give the character something to walk around on. So to make this character interactive, I am going to look in that Standard Assets folder that we imported, and I want to grab this ThirdPersonController script, and all I need to do is just left mouse click and drag, just drop this right on my game character and I am going to get this warning about losing Prefab. I am going to go ahead and Continue. It's okay. Basically, this is breaking the connection between our character model that's in the Project folder and kind of making a local copy that's just going to be used for this scene.
So I will click back in the hierarchy on our game character and I should see here I have got a couple extra components that I can see in the Inspector. So I have this Character Controller and this Third Person Controller. Both of these are scripts that are now attached to this game character. So I am just going to make a couple of adjustments here. Let's start by looking at the Character Controller. I'm just going to set some scaling here, and again, this might be different if your characters are slightly different size.
So basically what I'm doing here is forming sort of a rough shape that will represent the collider of my character. So this is going to kind of flesh out the rough physical shape and sort of help out with physics calculations that Unity will do during game play. So now let's move on to this Third Person Controller script and let me just expand that. What we want to look at here are these Animation Clips. So we've got the Script asking us for an Idle Animation, a Walk Animation, a Run Animation, and a Jump Pose.
So what I can do is look back to my Project panel, find that game character file, and I can see here I have got the animations that I've set up through my FBX Importer, and what I can do is just click and drag those over. So I am going to set the Idle Animation for Idle Animation. Walk for the Walk Animation and so on for Run and Jump. And there are a few other settings here as far as the Maximum Speed that the character can walk with, how high it's going to jump.
I am just going to leave these on defaults for now. One additional thing I want to do is add a light in my scene, so if I switch back to the Game view, let me just move my camera so I can see. So I want to just place that a little closer. Let me click here. I will click and rotate. Let me adjust this.
And I will click and drag this. So if we switch to Game view, I can see my character is very dark and that's because there are no lights in the scene. So I am just going to go ahead and add a directional light, so I will click GameObject > Create Other > Directional Light and then that will add this Directional Light to my hierarchy and let's go ahead and rotate this. Let me zoom in a little here. So I'll just rotate it so it's kind of shining on our character and if I switch to the Game and I can see that lighting looks a lot better.
So let's go ahead and click Play and we should see that our character has some interaction. So by clicking the A, W, S, and D keys, I should be able to make him walk around. So let's go ahead and click Play and see what that looks like. Okay. So I am clicking W here to walk forward, S to walk backwards, and I can turn using A & D. And if I hold down Shift, I can make him run. And I can jump with the spacebar.
So those are kind of the basics of using a script to add interactivity to your game character. In the next video, we will cover getting the camera to move around and follow the character as he walks and runs around.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 34608 Viewers
94 Video lessons · 24139 Viewers
100 Video lessons · 4820 Viewers
83 Video lessons · 9743 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.