Up-Down-Sideways... Coding Tic-Tac-Toe for Newbies | Ian Trowbridge | Skillshare

Up-Down-Sideways... Coding Tic-Tac-Toe for Newbies

Ian Trowbridge, Programming is my life

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
13 Lessons (1h 13m)
    • 1. Introduction

      2:03
    • 2. Setting Up The Project

      4:30
    • 3. Setting Up The Menu

      6:49
    • 4. Coding The Menu

      5:40
    • 5. Setting Up The Board Pt1

      3:12
    • 6. Setting Up The Board Pt2

      5:47
    • 7. Coding Our Variables

      4:26
    • 8. Coding The Game Pt1

      7:01
    • 9. Coding The Game Pt2

      5:53
    • 10. Coding The Game Pt3

      7:09
    • 11. Finishing Up The Code

      7:14
    • 12. Implimenting The Code

      8:28
    • 13. Completing the Game

      4:53

About This Class

In this class you will learn how to create your own version of Tic-Tac-Toe in Unity3D. You will also be taking away many helpful skills, and a good deal of know-how for any future coding endeavors you may have. You should have the Personal edition of Unity3D installed on your computer.

Transcripts

1. Introduction: everybody. Welcome to this tick tack toe tutorial, which is an introduction to Unity three D and the coding language. C sharp. What will you be doing in this tutorial? Siri's? Well, I'm glad you asked. What you will be doing is you will be creating a tick tack toe game in Unity three D. Using the scripting language c sharp The goals for this classes to teach you how to understand, read and code C sharp. The result. So to teach you how to use unity three D and the goal. The overall goal of this whole thing is for you to make a fully working tick tack toe stand alone game, which stand alone is basically a di e x e file that you don't have to install. It's a game you can just run immediately assumes you get it. What we will be using this class is Unity three D, as I've mentioned already, uh, to get that you go to unity three d dot com. Unity three D is a 100% free game making software, though there are packages that you can get that you do have to pay for. I don't recommend doing that you don't have to. You can if you wish, But I used the free version. It works well. When you get to unity three d dot com Something like this right here will pop up and the background maybe a bit different. Uh, when you do get here, get hit. Get unity now and you'll see all the different packages you get. Uh, you will be learning C sharp. As I have mentioned, this picture here is an example of C sharp. The benefits of learning C sharp is that it's a very powerful coding language that many, many coding areas different businesses use, uh, in the law a lot. A lot of gaming companies use software that requires good to be written in C sharp or job script, you know, see sharp. Then that means that you could get hired easier. Just saying, uh, that's all for this video. Thank you for watching and cannot wait to see you in the next video 2. Setting Up The Project: Hello, everybody. And welcome to this tutorial video where I teach you how to set up our unity project and how each of the unity components works. So what you're gonna need to do first is open up unity by hitting that desktop icon right there about two times after it pops up, you'll end up with the window like this one. And when you get to that point, you're going to hit this new project. But when you do, it will open up this window right here and it will ask for different fields like your project name the location in which your game is going to be stored. And then these buttons right here. I'll explain in a minute so you can name your project whatever you want. No, I want to do it. You can name it. Whatever you want. I'm going to keep mine fairly simple and just call it what it is. Which is the tick tack toe editorial. And you could change location that it is stored by either typing it in manually or hitting this three dot button, which will pop up with something like this where you can select different folder, then it asked down here if it's a three d game or a two D game? Well, tic tac toe is to d, so it's gonna be a two D game. And they asked about asset packages these air for a more complicated game. You can use him if you want, but for what we're doing, we don't need them. Okay, so then we're going to create a project when it happened. When you do that, what should happen is a couple of these pop ups should pop up, and then it will open up the game editor. So let's explain what you should be. Spew this down. Here is the assets area. It holds all of the different folders, all the different files that contain, like different images, different code and all that for your game. What we're going to be right now is right click and go up to create, and then you can see what l it would store down here, but we're going to create a folder when you hit that. It should pop up with that folder icon and, well, basically, what you see right there, and that means that you can name it when that's highlighted Blue. I'm gonna name my folder scenes because that's where we will store all of our scenes. They were gonna do the same thing again. We're going to call it scripts because that's where Mets, where we're going to store all of our coding files. All right, now, we've got the hierarchy that holds all of the game objects in this particular scene. Right now we have in here is a main camera because unity automatically generates the main camera. As you can see right there, when you click on the main camera or any other game object, it will pop up in the inspector window That will tell you the name of the game object transform of it, which contains the position values, the rotation values in the scale, values in any other components that you have on it. Like since it's camera, it has the camera component. We don't really need to mess with that too much right now. We will when we start creating the game. Uh, let's look at the scene when seen view window. So here is where you can edit all the game objects in the hierarchy, and you can view what it looks like right now how it's all set up if you want to see how the game actually looks. If it was being played, you go into the game view, and that will show how all these game objects, uh, look in the game. So now let's explain what each of these buttons right here do Here. The hand is where you can move around, grab it different areas and moving that direction. All right, so let's get back to the camera. Then we have this positioning button where when you click on a game object, you can position it and move it however you want. Then you have the rotation button where you can rotate it, however you feel. Then you have the scale button, which allows you to change how big or how small it is as you can see what's happening right here. And then you have this button, which allows you to scale it, rotate it and move it around. However you feel all at once, so that's all for this video. What we're going to be doing in the next one is actually creating a menu for the game 3. Setting Up The Menu: Hello, everybody. And welcome to the first video in this series where I teach you have to do something. So what I'm going to be showing you today is how to set up the menu for a tic tac toe game . So the first thing you're gonna need to do is open up unity. And when it opens up, have this window and you'll click on the tick tack toe tutorial or whatever you named the game. It will show the pop ups it pops up. All right, so let's go into our scene's folder. You see how it's empty while we need to see. So right now we're going to hit file and safe, seen as it will bring you to the Assets folder for your game. Double click scenes go into it in the name you're seeing. This will be our main menu. Then hit Save and it pops up down here. Double click it. Open it up. All right. So this is a main menu seen. All we have right now is the main camera. We're gonna change that. So, in the hierarchy, right click, Go down to you. I can hit panel. Now you'll see that it didn't just create a panel. It created a canvas in an event system. Now, if you create a U I object and you don't have a canvas or an event system, it will create one for you because everything that is you, I has to go into a campus. Unless it's campus so quick, let's click Canvas. Let's go over to the Inspector. You see this component right here, campus scaler. We're going to change it. The US scale mode. We're going to change it to scale with screen sizes. That way, everything in the canvas will always be the same size on any device. It will always look the same, I should say so let's click on our game view. This is what to the panel looks like right now. And it looks this way because it is set to stretch to match the width in the match of the height of the game view. Let's change that real change to middle center by hitting that button right there, and it changes the with values and height values to show it to show us what it actually is . And we need to change that from 800 to 300 or well, whatever years this and whatever the height is for you, we change that to 300 as well. Sweet. So our panel is actually set up toe. Look, right now, down here in the image component of the panel, you see how it has color right here. Unless you want your panel. Look, I you can change the color by using this right here. All right? I'm gonna change mine to a green color, and then right here controls the shade of it to make it brighter or darker. Okay, so whatever color you make it, you should set it as a preset. I'm going to leave my first preset because I don't know why have it anyways. Yeah. So that's how you change the color. So click anywhere else. Except for on that once you're done to get out of the color window and then we're going to change the name of our panel to main menu panel. Sweet. Make sure you hit Enter every time you change the name. Otherwise it won't change. Now, inside that main menu panel we're going to right? Click it. We're going Thio going to go down to you I If my mouse will work and we will go to image. All right, let's change the image. Name to title field. All right, Keep it. Well, actually, click on the middle center box and change that to top center. Now change the position. Why? To negative 25 James. A width of 300 to match the width of the main menu panel and change the height to 50. Do we want to have 50? Yes, we wanted 50. All right, then we will go down here to the image component. You'll hit this circle right here next to the sprite. Well, the source image section and we will go down to you. I straight that way. It has a rounded edges and it doesn't look square. Then we will go to color, and you can change it to whatever color you want. I'm gonna make a bit brighter than the actual menu panel. Click anywhere to get out that and then you've got your title field set up. Now we're going to right click on the title field. We're going to go to you. I and text. Okay, we're going to Well, okay, let's do this first change the width of 300 to match the title field. Let's change the height too. 50 to match the title field. Let's change the text. You can tell it to say whatever you want. I'm gonna tell it to say not that the main menu and then font style. I'm gonna change that too bold and change font size to 30. Then down here in paragraph, you're going to want to center it and hit a line by geometry in case title field shrinks or anything. It will always stay in the center. Then you can change the color change to whatever you want. If you want to change it, I'm gonna change mind. White. All right, so we've got the title field set up. Um, what we're gonna do now is right. Click on the main menu panel, go to you. Why? And button expanded to 300. Not 300 to 50 and 35. All right, the position why we're going to bring it up to about 70. All right? And then if you want, you can change the color of it. I'm not going to. Then you name your button. Whatever you want. I'm going to call it play now. Button and detects will be playing now. All right, Changed size of it. If you want changing 20 bold A line by geometry and then you can change the color of it if you still feel I will. And that, my friends, is how you set up a menu we're gonna do is go to file and save scene. Now, whenever we click on the scene or enter any other scene and then come back to this, it will always look like this. So that's all for this video. Sorry, I didn't think it be so long. In the next one. I will teach you how to code this menu. 4. Coding The Menu: Hello, everybody. And welcome to the next video in the series where I teach you how to actually code the main menu. I'm sorry. I had to split the menu tutorials into two parts. It was longer than I expected. And yeah, it's better this way. So what we're going to do is we're going to When you get to this point when you load up your game, you will go into your scripts folder You will right click, go to create and real quick before we click anything else. There are two ways that you can code in, uh, immunity. You can code in job script or you can code in c sharp. What we're doing is we're coding in C sharp, so we'll click C Sharp script. Since the text right here is in blue, we can name the script. Let's name it Main menu script. We will double click it to open it up in mono develop and there we go. It opened in modern developed, So avoid Start that when we initialize the game when the game starts. This is the function that's called. We don't need this As of the moment. Avoid update. This is called once for once, preferring. And that's good for if you need something checked every second or like less than a second, honestly, but, yeah, we don't need that either. So the public class main manuscript tells us the name of this class or this script and mono behavior tells us that this will use it will inherit behaviors and functions from on a paper. All right, so what we're going to type now is public. Avoid play now. Okay. So public void means that this function can be accessed outside of the script, either in the Unity editor or in another script. If it was private void or if it was just a void, we couldn't access it from another script. Okay, so what we're going to type inside of that is application. This hasn't auto fill feature, by the way, which means you can either type it all the way out or you can hit enter, and it'll fill it in for you dot load level. All right. The reason it has a slash fruit is because it's outdated. So there is another way of doing this, But this is how I do it, and it still works so why not? Okay, What we're gonna have to do here is put in parentheses and in between those parentheses. What we will do is we will type level one. All right, and then we're going to close it up. And at the end of each line in C sharp or in JavaScript, you have to put this semicolon to show that that lines ended. That's all you needed done. Otherwise, the game will not compile. All right. Okay. We're going to have Teoh do here, actually, let's show you something. Okay? So go above the public public void and type in public string. Um, level to load. All right. And in here we will remove the parentheses in the text. In between, not the parentheses. We will remove the quotes, the quotations and, uh, the level one text, and we will take in the level to load. All right, So what this means is that inside of the editor, whatever we type well, actually, OK, so whatever we type in as the string level to load well, appear here in the function. I'll show you what I mean. OK, so we're going to drag the main menu script onto the main camera. You see it right here. How? It has this field right here. Level the load. Type in level one. Okay, so then we will open up. Go down to our plane now. Button, open up button script area and drag. After you click the plus drag in your main camera when it says no function, go down to main many script and type and select play now. Sorry. So when we click this, it will call the It will tell the application to load the level to load, which we have put as level one. All right, so what we need to do real quick. Just save this click musing and then the file station as going to scenes. And you have to type this exactly how your level toe load is typed. Because it is case sensitive type in level one. It will save it. Now we go into main menu, make sure it's safe there, and we click that button for play. And when we hit play now. Oh, okay. Sorry. I'm smart. Okay, go to file. Go to build settings and click out open scenes to add the main menu and goto level one make sure inside of it and then hit at open scenes. Okay, so now when we click play and we click play now it takes us to level one. So that's how you set up the main menu. In the next video, I will teach you how to set up the tick tack toe game. Thank you all for watching. 5. Setting Up The Board Pt1: Hello, everybody. And welcome to this video where I will be teaching you how to set up your dick Tech toward the first thing we're gonna need to do is going to level one. When you get there, you can either go to this, create button and go down to you why and into panel, or you can right click and said the hierarchy go down to you I in select panel. When you do that, you, uh you need to rename the panel board now, As you could see, the board is set stretch to match the width and height of the game the window. We need to change the anchor for that to middle center instead. After you do that, the width and height values need to become 3 45 When that is done, you can change the color if you want to. I'm going to sweet. So we have our basic background for the great board. No, we will creating empty inside of the board by right clicking on it and hitting creativity. And after you have done that, you need to rename the game object. Grid lines don't change anything else and right click on the grid lines in the hierarchy go down to you. I and image. Okay, We need to rename the image grid Line one. After you do that to leave it at middle center, change the width to five and the height to 3 45 to match the board down here in sorts. Image none. Sprite. And the button Hit the button and scroll down to you. Ice. Great. That way it will have the nice rounded edges, as you could kind of see down there. All right, then. If you want, you can change the color. I will. All right. I'm going to duplicate that. Actually, one thing I should have done before I duplicated that. Sorry. Okay, Select grid line one again and type in 3 45 Divided by three. Divided by two inside the physician X column on What that will do is it will change the position to 57.5, which is exactly where we want the grid line to be. Duplicate the grid line and put a negative symbol behind 57.5 for grid line to And there we go. We have our vertical line set up. Now what? We need to do is right. Click Grid Line to duplicate changed position x 20 and changed the with 23 45 in the height to five. After you've done that, type in 3 45 divided by three, divided by two into the position Wide box. One more duplicate Great Ally three. To get good life for and put a negative symbol behind the 57.5. And there we go. We've got the basic Tic tac toe board set up in the next video. What I will be doing is showing you have to add buttons into each of these boxes. That way we can code each of them to show up in X or no when we touch them. 6. Setting Up The Board Pt2: Hey, everyone. And welcome to the next video in this series where I will be teaching you how to finish setting up your game board. To do this, we need right click on the board and go down to create empty after that have been created. We need to rename that two great buttons after you've done that, right, click on green buttons in the hierarchy and go down to butt in. And now you can see we have a button game object. We need to resize it to 100 by 100. And then I think we can leave everything else the same unless you want to change the color of it. And I don't have any colors that are particularly pleasing. So I'm not gonna change mine. We need to rename this button to grid, but one no. Each of these buttons were gonna make nine of them total. Each one has to go in one of these boxes on the great. All right, so they have to stay in a particular order like red button. One is up in this corner. Good button to right next to it. Then three, then four under. Great button. 156 and so on. All right, so let's position that in the top left and change position X two negative 60 five and then position. Why will be 65? All right? After you do that, you can duplicate the button. Change the anchor to top center change position extra zero and then duplicate green button to changed the anchor to help. Right? Position it at 65. Duplicate green button one, which will give us great but for change. The position to middle left dropped the position wide. 20 Duplicate grid button for it. Get great button. Five. Set the anchor to middle center. Changed position X 20 Okay, guys, only four more duplicate. Created, but five to get group, but in six change the anchor to middle right Changed position X to 65. Three more duplicate grid button for to get great, but in seven change the anchor to bottom left changed position. Why? To negative 65. Sorry I missed that. I need to say at 100 then duplicate. Good, but in seven to get great button. Eight. Change the anchor to bottom center. Change the position X 20 duplicate. Great button eight to get great about nine and then change the anchor to bottom right and the position to 65. Now open up in the hierarchy All the great buttons to where we can see all their Children, which is just text. Now click on one texts, then hold down control and hit every other text. When you have highlighted all those, you see the text script right here and they all say button, change the text to nothing. Just a race. The word button set the front salad a bold in the font size too 40 All right. And that is all we need to do here. And you may close those up as I have done what we're going to do right now, real quick is set up a button above the board on each side to tell us whose turn it is. So right. Click on campus, select you why and button and dragged this button above the board, and we won't really see it yet, but change the width to 100 in the height to 100 and changed position to top lift. No, we're actually do better. Center changed position. Why Teoh? Let's see. Let's do 50 75 then change position X to Native 65. Negative 70 until it's in that corner. So about 1 15 all right, that's very position. There's 1 15 people rename this button to Player X and then change the text Teoh X and change the font size, too. 84 into the font style. Too bold, and we'll leave that like that and duplicate the player X button. Drag it right above the player X button and rename to player. Then you reposition it to positive 1 15 and then we just need to change the text to Oh, all right. So that is how we set up our board. You can't really tell what it looks like right now in the game because we don't have an aspect that can show you everything. So, yeah, In the next video, I will be teaching you how to code your game 7. Coding Our Variables: Hello, everybody. And welcome to this tutorial where I will be teaching. You have to code. You're a tic tac toe game. The first thing we're gonna do is go into her assets folder. And when we were there going to our script shoulder, we will right click in the scripts folder and go to create and then see sharks cream the text for the seas C Sharp script is highlighted between you can edit it, and we need to change the Texan to read game controller. After you have done that, double, click it to get it to open up in mono developed. If it will do that, it's less sometimes. All right, set up. Okay, so what you need to do is in between using unity engine and using system collections. We need to type in using unity engine you are. This will give us access to coding, buttons, toggles and sliders, all that other good stuff. What we'll do now is a race of the void. Start in void, update functions and type instead, Public player, Player X and then under that type in public player on no player. All right, As you can see, the player is, uh, highlighted. Red highlighted. It's ready. This means that it doesn't have a definition for player. We're going to create one by doing above the public class game controller, Square bracket system dot serialize herbal and hit Enter n type public class player. What this will do is set a definition for the player, uh, component Inside of that class. We'll do public image panel, public text text in public butting. But all right, we'll go back into the public class game controller and we will type Sorry, public player, color, active player color, and then under that do public player color inactive player color. Okay, as you can see player color, we do not have a definition for that. So we will highlight that right click and copy. And then we will tell you above the public Last game Curler square bracket system dot serialize herbal. Well, the public class paced to get player color and then our curly records. So now player color, we have a definition for it since they're blue. Inside of that, we will take public color, the panel color and public color text color. All right, so now that data set up, we can get into actually coating this. We will under the public player color and active player color. We will type public text in your square brackets, which will turn it into a group of text objects so you can add multiple of them. It's kind of like an array. Then you will take a private and move count and then private. If I could spell that right private string player site. Okay, so that's where all the variables we need. We're going to get into setting up the functions in the next video. 8. Coding The Game Pt1: Hello, everyone. And welcome to the next video in the series where we finish coding the game controller script. What you need to do is open it up by double clicking on it and it will open up in mono develop. And then, as you can see, this is all the code that we have done in the last video. We need to go under the private string player side and we will create our first function. Function is void awake. So basically, when the game starts, we wanted to set the move count equal to zero, and and then what we wanted to do is call this function sit game controller reference on buttons. I know that's a pretty long function name. So we're gonna do is we're gonna copy it and then click enter under to get under, avoid awake and in real type void control V to get set game controller reference on buttons and then our brackets not brackets, but parentheses. Site. Now we do our curly records. In between the set game controller reference on buttons, we will type four int I equals zero I less than button list dot length and then I plus plus in between the curly brackets that we have made After that statement, we will type button list I dot to get component in parent. I don't know why that cut me off, but it did so and then the grid piece parentheses dot Set game controller reference for this. So what we need to do is we need to create a a great piece script. So let's save this by hitting. Control s on going into unity, right? Click in the scripts folder and it creates and see sharp script every name it to great piece. When that has been saved, we will in my developed and then we will type in between using unity engine and using system collections using unity engine. Oh, no. What did you do? Sorry, unity engine dot You I now, after the public last great peace, we will type public button, but in public text but in text. Then we will also take private game controller game controller. Make sure that the G is lower case in the second game controller. Then we can erase, avoid up, avoid starting void update and weaken type public, Boyd set game controller reference and actually leave the parentheses. Open and type game controller controller in between. Close it off and create your early records. Then tight game controller. The lower case one equals controller. All right. And then to save us some time, we will also take public void set space in between net. We will take button text dot text equals game controller died no dot Get player side. You do not need those curly brackets. Site the new able tight button that interact herbal equals boss and game controller dot and turn. Now, we do not have the function in turn and get player site yet, but we will in just a few moments. So yes. Um, don't worry about that air yet. And as you can see, we now have it glowing blue, and it actually works, right? So we will do now is way will add more code under that, starting with Boyd start game. And in between those curly brackets, we will typeset starting, decide And we will also set board interactive All Jeez, I can't type and then set player buttons false. All right. We don't have any of these functions yet. We will in a minute, though. So, under avoid start game. We will type. Avoid set starting side and then do your curly brackets. Then hit. Enter a couple times and type. Avoid set player buttons. And in between those parentheses, we will take full taco. Then close it off of your curly records. Then one more thing. We will go enter twice and then types avoid set board interactive all. And we will have a full title here. So we will leave the back of the parentheses open. Close them after we write that. And you are curly brackets appear in the set start game function. We will in between the set board interact herbal parentheses we will type true. All right. So in the next video, we will work some more on these functions and hopefully finish the script. 9. Coding The Game Pt2: Hello, everyone. And welcome to the next video in this series on coding game. If you open up your game controller script in mono developed, you can see that we left off with some empty functions. We're about to make those not so empty. So in void set, starting side we will type if this would work, uh, set player colors and inside the parentheses player X comma player. Oh, all right. And we will work on dysfunction in a minute. What's going to avoid set player buttons? Bull toggle to player x dot button interact, herbal equals toggled and player Oh, got interact herbal. Oh, no, sorry. That button dot intractable Sorry I was getting ahead of myself equals toggle. And then let's go into void Set board intractable and type a four statement for rent. I equals zero. I is listening button list God length I plus plus curly brackets inside the curly brackets . We will type button list, uh, button list. Sorry. Square records. I closing square bracket get component in parent, but died interact. Herbal equals tuggle. All right. It's basically what this is saying is any button that is in the button list you will look in their components for the button component, their parents components for the button component, and then you will set it to interact. Herbal uh, either on or off, depending on what the toggle is. So those functions air done. Let's hit Control s to save you want to save frequently, just in case your computer ever messes up and shuts down or anything? So then we will type. Avoid set player colors player. New player, comma player, old player in Tikrit, Curly records. Okay, inside those curly record tool type new player dot panel dot If that would not be capitalized, I'd be great dot Color equals active player color dot handle color. And then, if we could copy this, we hit. Enter and then click control beat and we will put in place a panel text and then active player color died text color. Now we copy both of these and go under and hit Control V and type old player in place of new player. And instead of active player color, we change it to inactive player color into the same thing again. Old player and then inactive player color. Why is the panel dot color wrong Well, let's look. That would be why we need to change that to a lower case panel and public class player. All right? And that fixes the air. It control s. And then we will do another void set. Oh, boy. Set player colors inactive. We will type player X got panel. Dr. Color equals in active player color dot Handle color. And then we will take a player. Ex dot text Dr. Color equals in active player color. I got a text color. Now we will copy this. These two lines, we will go under and paste them and in place of the player Exhale type player. Oh, and we have finished that function as well. Now, real quick to get rid of the error that was in the grid piece, uh, script. We will take public string, get player side, and we will type return player side. So basically, what this will do is win. The great piece calls the function game controller dot get player side. It will return the player side value, which will either be in X or no. In the next video, we will work on setting up the intern function to where it will tell us if we have won the game. If we have drawed, if we have created a draw or if way need to switch sides. All right. So I will see you in the next video. 10. Coding The Game Pt3: Hello, everyone, and welcome to the next video in this series over coding your game. As you can see in the console, we have an error from the grid piece saying that the game controller script does not contain a definition or function for in turn. So that's what we're going to create. Open up your game controller, and when that opens up, go under the public string, get player, site and type, public, avoid and turn. So this is going to be a fairly long function, but it's very necessary. So if move account is less than nine and then create your curly brackets, then we type if the button list. But zero Doug text equals player side and let's copy that and paste it and the button list . But one dot text equals player side, and it's simple. And if the button list but to dot text eagles player side curly brackets in between those we will type game over player side. All right, we will hit control s Then we will highlight this if statement and copy it and then hit Control V, you will type if button lists uh, instead of zero, we will take three dot text equals player site. And but list for the text. Eagles player side button list five dot text equals player side. Then game over it up later side. And now we will pay Suszkin instead of zero. We will put six instead of one. We will put seven and instead of two will put eight. And now we go under and copy. And while we pasted to Sorry, we pasted again and it said, Is your Well, no, we need the zero. Actually, instead of one, we put three. And instead of sick two week six, then we won't face this again, and we will put instead of zero, we get one instead of instead of one. We get four instead of two. We get seven well, paced it again. And instead of zero, we get to instead, Uh, wait. Sorry. Uh, instead of zero, we actually get Oh, no. Is right. Okay, too. Instead of one, we will gives, uh, five. And instead of two, we will get eight. So I'm trying to keep track qualities. Uh, So instead of zero, actually, no way will keep the zero. And instead of one, we will get four, and instead of two. We will get eight and one more time of this. I think we will do if button this too instead of one will get four instead of two. Look in six. Okay, so that was fun, wasn't it? The reason this is showing Red is because we don't have the game over function get. What we're gonna do is we're gonna copy from if to the second. Well, the bracket. Right after button list 24 and six. We're gonna copy that. We're going to paste it and we will put if move count is greater than or equal to nine. We have all of this, but instead of saying game over, player side, um, we're going to go up real quick into our variables and we will put public cool. Is one all right? Okay, so on awake, we need is one to equal. False. And then let's copy is one. And bring it down into here instead of player side. It is. One equals true. All right, slow. Then we need to put in our, uh, cynical. So copy that statement is one equals true and paste it in all the following if statements so instead of game over. Player side will have is one and what this does. The reason we have is one is because if we have one way needed to say, uh, we have a draw, so go outside of that. If move count is greater than or equal to nine function and we will put, uh, this is one equals equals true. So if is one is true. We will do game over, uh, player. Oops. It will equal wrong. All right. And then, uh, if Oh, no. Yes. Okay. If is one equals equals false. So if is one is false way needed to say game over and then player beside. And then we go out of those if statements and we type else. Sorry, curly bracket change. Besides, James site already. So, um, I did miss up here somewhere that see, we could put another bracket. That one. All right, there we go. And now, in the next function, we will be changing changing the sides and finishing up this script 11. Finishing Up The Code: Hello, everyone. And welcome to the final video of coding our game. Uh, here we are in the game controller script, and we left off with this massive function which is public void in turn, real quick. And the else statement changed side and new change that to change sites because that just sounds so much better to me. So we're going to type, avoid change sides, curly brackets, convivial type player site equals player side people, people. Thanks. All right. And then we will question Mark oh, capital and X capital. So basically, the player side will become, If it's if the player side is exit will become Oh, and if the player site is oh, it will become X after that. In the same function, we will type if player side equal equal X inside this curly brackets player colors player X comma player. Oh, no, After those curly brackets Reltec else Curly brackets, spent player colors, player Go player X already. So that's how we change our sides and set the colors for the player accordingly. Now we will create another function to take care of this game over error. Uh, it will be called Boyd Game over imagined that. All right, Inside the parentheses, we will type string like a tight winning player. All right, so inside of those curly brackets will type it a winning player equals equals wrong. Real type. Set game over. Text inside those current disease, it's a draw in the old type set player colors inactive. All right, then we will type after the curly brackets else. Curly brackets. And inside of those set game over text a winning player, plus winds put a space before the winds. That way, you've got a space when it says who won. And then, uh, after the else statement, we will take a restart button. Not set active. You betrayed and set aboard. Intractable. Okay, one more function. Actually, we have two more. This is the last one down here. Okay? Public. Boyd, restart game, and we will put, uh, move. Count equals zero. Um, restart button equals Oh, restart. Button that set. Active. It's false. And, uh, came over panel is, uh that's active. It is false. Okay. And then we will also put Sorry, I've got this, uh, start a game and four and I equals zero. I is less than the button list. Uh oh. Lord button list dot length and I plus plus. And, uh, what we will put inside of these curly brackets is button list. I I got a text. Sorry equals nothing. Okay, so it kind of looks like this, uh, added more issues thing. Good. Then it fixed. But that's not the case. We're going to do one more public void, and we will call that function down below restart game, And it will be called, uh, avoid game over, not void. Game over. Very sorry. Uh, set game over text, and we will spring value. And inside of those curly brackets, we will put game over. Panel died set, active, true and game over. Text typed text not set. Game over. What did this do? Game over. Text text, people's value. Okay, so we will go up to our functions and we will tie below. Public bull is one public game object game over panel and public game objects game. Uh, no restart, but and then one more public, the game? Uh, no, actually, this would be a text public text game over text. All right? And that we'll fix all of the air's down here. Okay, So control s to save, and then I will see you in the next video. 12. Implimenting The Code: Hello, everybody. And welcome to the video about implementing the code. One thing we have to do real quick because I did not have enough time and did not realize is, um, in a void set starting side we need to put later side equals X. All right. And after we have that highlight, avoid start game and parentheses next to it and set it in here plates, Uh, a semi colon. All right. And then we're done coding altogether. Now, to implement this, go back in the unity and right click in the hierarchy and hit. Create empty reset. The transport transformed a zero hitting this cog, uh, cock button hitting reset. Rename it to game controller, and it add component scripts and game controller. Now, there are a lot of different variables this so it's not as bad looking as it seems. So it's asking us for a player, X panel, text and button. So take click on the player X and hold it and drag it into the image. I mean, it's a panel. Take the text that is a child of the player X panel and insert that and insert player X uh into the button. area as well. Then we do the same thing for player. Oh, and now what it's asking is when it is the players turn. What do we want the panel color to be, Which is this white part? And what do we want to text color to be, Which is the extra vo? Well, if it's active, I wanted to be green, and then I want to text to be read. I went to the green. Uh, you'll want to change the, uh, this section right here to white all the way. Otherwise the button will not show up. Okay, so we have the active player set, and when it's inactive, the text color is only thing I'm going to change. I'm going to change that to white. Okay, Make sure if you didn't change the panel color that you change this bottom bar to pure white That way, Panel still appears now in button list. It asks us for the list of the different text objects set asides to nine. And then you see this lock button right here. Click that that way. When we click on something else, it won't about that. Okay, So open up. The great buttons where you can see that they're checking their text. Sorry. Text Children and starting at grade button one insert detects agreement to but in element one. Great button three. Put it in a moment to but four and all of it. Three and so on so forth. It takes here a moment, but you get it. All right. Um, this is one check mark. Leave it unchecked. The game needs to handle that. Then you can close that the great buttons if you still feel. Because we're not gonna be using those right now. And it s fair game over panel and a restart button in a game over text. So we did not create those. That was something I left out because I didn't know if I was going to do this. We're going to create a panel by right clicking on the canvas, going to you, I and the panel, and we're going to shrink it. To where? Unlock that. Hidden a lucky kid. It's set to stretch right now. When you said that middle center changed the width to 200 Change the height too. 100. Okay, change the color. If you choose, I will it makes it a solid green. You can change the width. If you want to make it longer. I'm going to change mine and then height. And that is the image for the panel. We need to rename that two game over panel and then right click it and go down to you. I and text, um, keep it at middle center. Changed the wit to 300 or the size of your game over panel. And I hate to the size of your game over panel. Mine is at 75. That's why. Okay, uh, changed a text to game over, and the game should take care of that. Change the funds out of bold and the font size to 20. Go down to paragraph and change the alignment to center. After that's done, you can change the color if you want. I will. And then yes, that is all. You have to do their click on the game controller game object again and drag in the game over panel and drag in the game over text. All right. Uh, right. Click on campus again and hit a button. And then, uh, we're going to change the position of that too. Negative. 75. And you can change the color and the image script section. I will. And then button, uh, hit the addition symbol right there in the on click section and Dragon game controller right here. Go down to know, hit game hit no function and go down to game controller and hit Restart game. All right. You'll need to rename this to restart, but and text. You could change it to restart and change the color of it. All right, then. Hit game controller. Yeah, and drag in the restart button. So now when we play, it should set. No, it doesn't go into I know what I did. All right, uh, open up the great buttons again. Uh, hit. Great button. One hold down shift and hit grid, but nine to select them all it add component scripts in great piece. And then, for each one, you have a great button and a text. Drag the grid button into the button section in the text into the text. I'm gonna pause this so let you guys do that real quick. So now that we have finished inserting the button and button text into the grid piece script, but we need to do is click 100 button one and go down to great but nine and hit that holding shift, which will select them all hit the plus symbol. Now click on red button one drag grid button one into the nun and hit no function grid peace and sets face. Do this for each of the nine great buttons. All right, And then once that's done, open up your game controller script one more time. And in start game, put game over. Panel died set active, false and restart button. Died set active. False. All right. And that should be all we have to do for this. Yep. All right, um, in the next video, I will be teaching you how to set up the game for a dot txt file. And as you can see right now, the game works. 13. Completing the Game: Hello, everyone, and welcome to the final video in the Siri's overturning your game into a dot txt game. To do this, we need to do three things real quick. Okay, so Player X and player Oh, select both those and put them in the board. Okay, then hit the canvas. And in canvas scaler you I scale mode said it to scale a screen size if you haven't already . And what's that? It's done. There is one bug that I just realized. Open up your game controller script and in between the if move count is less than nine. And if moved count is greater than nine type new account plus plus, and that will allow us to tell if we have a drawer night. But that compile. And when that is done, we should have no errors. All righty. So that is done. Let's go into our main menu. Let's save the project and then going to build settings. Okay, so select PC Mac and Lennix Standalone. Select your target platform, which will either be Windows Mac or Linux. I have windows, so that's what I'm targeting. Then you can choose the architecture, which is either X 86. If you have a 32 bit operating system or x 86 underscore 64. If you have a 64 bit operating system, if you have a 64 bit operating system, you could do either. But X 86 underscore 64 will probably work best. I have a 64 bit operating system, so I am doing that. Then in here, when you hit player settings, you can see all the different settings for your game. You can change the company name to match yours. That's my company name, and you can also change your product name. I'm just gonna change my to tick tack till and the product name will show up if you're doing something for Android or iPhone. But we're only doing this for PC Back and Lennox. Then you can change your icon if you have one to change to, which I don't. So I'm not worrying about that. And don't worry about the cursor endless. You need it in the game, which would be like if you're trying to click to go somewhere. Then there's all these different settings for changing the resolution of the game, uh, overriding to like change the size of the icon. Then there's stuff for, like, a splash image and all these other random settings. Top two. Maicer Game. I don't really mess with those you can if you feel like, but we're not going to. In this tutorial, you can hit build, and it will take you to your tick tack toe tutorial folder. Uh, right click and hit full, uh, Holder to create a new folder. And you can rename that to what everyone? I'm going to name it to Peter Build, go into it and then down here in the file name, type the name of your game, and then it's safe. It will compile the scripts it will build scenes in the resource is and compile the shared assets. Then process. And then it should open up the folder for you. And it did so real quick. The tick tack toe application and file folder. They have to stay together in the same folder or in the same area. So say the tic tac toe game was in her desktop. That would mean that the tick tack Toe Data folder has to go with it. So let's go to my desktop and we see the game in the data folder Open up tick tack toe and changed the resolution if you want. And windowed means that it will be like a window like this that you could drag ground and close. Otherwise it will be full screen. Uh, then you could change the graphics quality. I'm keeping it at a fantastic and then hit play. By the way, that's where your splash image would have appeared. Where that may make a unity thing. So as you can see the start game changing the resolution of the game, uh, when you started should allow us to see the whole board. I haven't. So yeah, that's why it's not showing up. Let's see. So let's see a draw real quick. Oh, no. Okay, X one that Sorry. Um, let's see. X one. Let's let Owen. Okay, I'm not that smart, so don't judge me. 00 Wins. All right. And then you can go into a draw if you wish. Each time you start the game, X will be the first person, and then I will always be the second, as you can see. So, yeah, that has been this tutorial, Siri's. And please recommend this to your friends. Have a nice day