Unity For Beginners | Jedidiah Wagner | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

15 Lessons (1h 50m)
    • 1. Intro: Unity For Beginners

      2:25
    • 2. Unity: How To Install Unity

      2:29
    • 3. Unity: Interface

      2:35
    • 4. Unity: Create & Edit Objects

      1:32
    • 5. Unity: Camera Controls

      3:37
    • 6. Unity: User Input

      4:24
    • 7. Pong 1: Scene Setup

      10:41
    • 8. Pong 2: Player Movement

      15:57
    • 9. Pong 3: Ball Movement

      17:21
    • 10. Pong 4: Scoring & Reset

      10:09
    • 11. Pong 5: Game Over

      16:31
    • 12. Pong 6: Sound Effects

      8:24
    • 13. Pong 7: Pause Game

      5:45
    • 14. Pong 8: Final Build & Exit Application

      4:54
    • 15. FAQ: Lighting

      3:05
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

24

Students

--

Projects

About This Class

Description:

This course is broken up into two distinct parts.

  • In the first part of this course I'll be showing you how to install the Unity game engine and create your very first project, as well as giving you a brief rundown of the UI & Engine.
  • Then in the second portion we'll be creating a 3D pong clone together from start to finish, using the C# programming language. During which I'll also be adding in some extra information so that you can actually take what you learn in this course and apply it to your own projects!

Prerequisites:

  • An understanding of the basics of the C# programming language.

*If you've completed my "C# For Beginners Course" here on SkillShare, you're good to go!*

Why Unity:

  • It's the most popular game engine for indie game developers due to its user friendly interface, reputation, and for its ability to create both simple and complex projects for nearly any platform.
  • It has the largest online community due to its popularity making it easy to find help, tutorials, etc. when needed.
  • It also uses the C# programming language, which is not only easy to learn, and in high demand but, is taught by yours truly!

Who This Class If For:

Anyone who is fairly new to C#, looking to improve their skills by applying what they know to a real application.

Aspiring game developers looking to begin their game dev journey.

Anyone looking to add to their personal portfolio.

Indie developers wanting to delve into and or take a look at the Unity game engine.

Meet Your Teacher

Teacher Profile Image

Jedidiah Wagner

Course Instructor

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Intro: Unity For Beginners: Hey everybody, My name is Jedediah. And in this course we're going to be doing a couple of different things. First, we'll be installing the Unity game engine, creating our very first project and taking a brief look at the interface. Then afterwards we're gonna go ahead and create our very first game in 3D. Being upon clone has oftentimes when first getting into game development, they're often told to start with something simple, like a Tetris, Tic-tac-toe or even upon club. So that's what we'll be doing. And as we create our game, I'll be giving you some extra information along the way. And it will also be going back over our code together each time so that you can apply what you learned here to your own project. Also, just a heads up, although the video I have running here in the background is a preview of the final project. This video was recorded at a lower frame rate than the game was running at. This was why the ball appears to be legging behind as much as it is. So basically what I'm trying to tell you is that our finished project is going to run smoother from the one you are seeing now. Of course, this was assuming that you decide they copy the same values that I use in the videos. And your own project, as we will be making our game easily and highly customizable so that you can make it your own. Now, just a heads up, although this isn't a direct follow-up to MIC sharp for beginners course here on Skillshare. I will be teaching this course based on the assumption that you have already finished that course. So if you haven't, I highly recommend you do so unless you are already profession in C-Sharp. So anyways, like I was saying, we're going to go ahead and start this course off by installing the Unity game engine together. Then we'll go through a brief introduction of the interface. And finally, we'll finish up by creating a Pong clone in 3D. Then once that is all said and done, you can head over to the projects and resources section of this class, where you'll be tasked with the challenge of creating your very own Breakout clone from scratch. I'm giving you the opportunity to utilize everything you've learned throughout this class and really put it to the test to help solidify your understanding. So if you are new to Unity game development or C Sharp, or just want to improve your skills, then this course is for you. So let's get started. 2. Unity: How To Install Unity: In this video, I'm going to show you how to install Unity. So the first thing you're gonna wanna do is type the Unity download into the Google search bar. Next you want to click on this, download unity. Then click on the button that says download Unity Hub. And it should start to install. Once let us finish installing, go ahead and open it up. Then go ahead and accept any additional prompts. Then it's going to ask you to choose your install location. Go ahead and pick any location you want and hit Install. Then go ahead and click Finish. Once you're at the Unity Hub, the next thing you wanna do is download a version of Unity. So you'll want to go to the install section and click Add. It should automatically select the latest version. So you have to do is click Next. And then it's going to ask if you want to add any modules here and install, you can either add these now are at them at a later time. Right now, I'm just gonna go ahead and click Next. Then just go ahead and accept the terms and conditions and hit Done. Then go ahead and accept any additional prompts and wait for it to finish installing. If you get a Windows security alert, go ahead and allow access. If he did not get this, don't worry about it. Once it has finished installing, you'll want to go ahead and create your very first project. So go up to the Projects tab and click. Next. You'll want to select the 3D project template. Then under the settings you wanna give it any name you want and choose a location for it to install and click Create. Once again, if you have any windows security alert pop-ups, just go ahead and allow access. Once the project has finished opening. And it should look something like this. If it does look a little different, don't worry about it. So now we have successfully instilled the entity, created our very first project. In the next video, we'll go over all the different windows you see here will go over and not only what therefore, how to organize them to your preferences. And then I'll do a little bit of additional setup. So thanks for watching, and I'll see you in the next one. 3. Unity: Interface: In this video, we're going to be going over the different windows here in Unity. So when you first create a project, these are going to be the main Windows you'll be using. So first off, we have the scene window or view. This is your interactive view into the world you are creating. It is used to position, manipulate, and modify all of your game object. Then you have your game view. This represents what your game actually looks like as it has rendered from the cameras and your game. Next we have the hierarchy window, which contains a list of every GameObject in your currency. Then you have your project window that displays all of the files related to your project. And this is where you will mainly go to find all of your assets and other files. Next, we have the inspector window. Gameobjects in Unity are made up of things like scripts, lights, sounds, etc. And the inspector window is what gives you detailed information about your currently selected GameObject, including all of the attach components and their properties, allowing you to modify the functionality of your game object. Then lastly, you have your console. This is what shows logs of messages, errors, and warnings. Now, if you don't see the console window, I'll go ahead and show you how to add that. So what you wanna do as you want to go up here to the window tab, go down to General, and then click Console. Then you can go ahead and place the console window wherever you'd like. Now, there are other windows in Unity. But when first starting out, these are the main ones that you'll be using. So one thing I did want to go over with you is how to customize your workspace. And all you have to do is click and drag any window to wherever you would like. As you can see here. Another way to edit the layout of your windows. So 0 up to the Window tab, go down to layouts and then select one. Another thing I suggest doing as far as set-up and say go over here to the Edit tab, go down to Preferences. And then inside the colors tab, you'll see one that says Play mode 10. You'll want to make sure to change those to something other than the default. And what this does is it makes it so when you run your game, the whole window will change colors. That's useful to know when you're in play mode because game object properties that you edit well in play mode, do you not safe when you stop the game? Anyways, looks up for this video and the next zone we are going to go for how to spawn in objects. And we'll also go over how to position, manipulate, and modify them. So thanks for watching and I'll see you in the next one. 4. Unity: Create & Edit Objects: This video will be spawning in our very first object and editing its properties. So to spine on an object, all you have to do is go to the Object tab here at the top. Then we'll get onto a 3D object and click queue. Notice that it appears in the hierarchy showing that it is now in our scene. And the knowledge properties are over here on the right in the inspector, here in the transformed section, you can edit its physician, can also edit the rotation along the x, y, and z axis and the scale. Another way to edit its position as manually in the scene itself. So you can click and drag any of these three arrows to move it along the different axis. You can also change its transform along multiple axes at the same time by using the square in-between the arrows like so. Up here at the top, you also have the rotate tool, which allows you to rotate it along the axis here in the scene VM. Here you can change the rotation by clicking and dragging on these different colored lines. There's also a scale tool here at the top to allow you to scale it within the scene as well. Once again, you have one for each axis, and you also have this metal one to move it along all three equally. Anyways, that's it for this video. And the next video we'll be going over the different camera controls to move along your scene. Anyways, thanks for watching, and I'll see you in the next one. 5. Unity: Camera Controls: In this video, we're gonna be talking about camera controls for navigating the scene view. Up here in the upper right corner, you have your siem gizmo, which displays the scene view cameras current orientation, and also allows you to quickly modify the viewing angle of it. As you can see here, you have these different arms labeled x, y, and z, and you can click on any of these to go to that specific. You can also right-click on the scene Gizmo to get a list of viewing angles. If you wanted to return to the default viewing angle, you can right-click on the scene goes morale, and click free. You can also toggle between a perspective view and an isometric view by clicking on the center of the scene gizmo, or clicking on the text below. You can pan around the same by clicking down on the scroll wheel and moving your mouse. Or if you're using the hand tool, you can just left-click and drag. While in the scene view, you can use your arrow keys to move around as well. Up to go forward, down to go back, and left and right to move side to side. Also, if you hold down the Shift key, you will move faster. Next, if you hold out for Windows or option for macOS, and then left-click and drag. You can orbit the camera around the current pivot point. Also, while holding Alt or Option, if you right-click and move your mouse up and down, you can zoom in and out. This can also be done by moving the scroll wheel up or down. You know, if your mouse up to zoom out and down to zoom in, holding shift will increase the speed I was aiming as well. By holding down the right mouse button, you will enter fly format, which allows you to move around the scene by using the W, a, S, and D key W to move forward as to go back and, AND to move side to side. By holding the Shift key, you will once again, maybe quicker. You can also use Q to go down and to go up. Also, while I'm flying through moon, moving your mouse around will allow you to change which way you are facing, therefore adjusting which way you'll be moving. While in fly through mode, you can move the scroll wheel up and down to change the camera speed. If you go up here to the top and click on this camera icon, you'll get a list of camera options to change. And you can mouse over each one of the names to get a description. You can change things such as the field of view, dynamic clipping camera using an acceleration as well as the speed. Now you do have some camera controls for when you are not on the hand tool, such as holding down the middle mouse button to Pam, holding down Alt or Option plus left-click torpid. Using the scroll wheel to zoom in and out, or Alt plus right-click. Then the last one I wanted to show you is how to center your view on a gameObject. To do those, Let's go to GameObject here at the top, go down to 3D object and spawn a queue. Then you can either select your Q by clicking on it and listening with the Move Tool selected, or you can click on it here in the hierarchy. Then with your mouse hovering over the scene view, just click at this feature found in the menu bar. Just go to Edit and then to frame select it. You can also lock your feet to the selected item by holding Shift and then clicking app, or by going to Edit. And then to lock for you to select it. If you unlock your current rotation, you can click on this lock here at the top rate. Anyway, it looks up for this video and the next video we'll be creating a script to get user input. So thanks for watching, and I'll see you on the next one. 6. Unity: User Input: Unless for the OH will be getting key input from the user. So to start, let's go ahead and create a brand new C-sharp script. To do that, go over here to the asset section, right-click, go up to Create, and then click C Sharp script. Then we'll go ahead and name those key and then double-click on it to open it up. Now inside your script, you'll notice there's two different methods. Us start method, which is called before the first frame update, and then update method which is called every frame. For getting input, you'll want to use the update method as you'll want to check for the key input every frame. Now there are a few different input methods. And we're gonna go ahead and go over three different ones today. And the key input will be using as the spacebar. So start, we'll create an if statement. And then inside our condition, we're going to say input with a capital I, get key down with a capital G, K, and be open and closed parentheses. And then inside of those parentheses, we're gonna say keycode, the capital K and C. And then you're going to want to put in the key value. Notice that there's a list of them here that will pop up. For this example. Like I said, we're going to use space. So we're just going to type space with a capital S. And as you can see, it popped up there. Then we use open and close curly brackets. And inside we're going to say debug with a capital D dot log of with a capital L, O, and then close parenthesis, and then quotation marks inside. And we're going to say pressed down. Then we're going to go ahead and copy and paste those twice. Debug dot log by the way, is what is used then Unity to print text to the console. Then unless one we're going to change it got key down to get key. And then this bottom one, we're going to change it got key down to get key. Then we're going to change the text inside both of these. So unless we're gonna save button held in the bottom one, we're going to say like go out button. So the difference between the J key down is when the button is initially press down. Guy who's gonna go off every frame as long if the button is held down and then get key up is going to be activated. When you let go the button. Anyway, just go ahead and save this. Then we're going to take this script and drag it onto our main camera. Because if your script as in the scene and there's not going to run. And if you go to your main camera and scroll down to the bottom, we can see that our script has been added here. Then you want to make sure that collapses selected and will collapse does is put duplicated text in the same spot. And you'll see that here in a second. Then just go ahead and hit play. Once you're in play mode, you want to click on the game via window just to make sure that it's going to detect your input. Then I'm gonna go ahead and press and hold down on the space bar. Now as you can see, it says button pressed down once. And then at a saying been held every frame. And you can see like counting up here. Now when I let go, it's going to stop printing out. And it's going to print out echo button. And you can see that here, the manager and go to Edit and land. So like I said, and put that guy key down is going to run anytime the button that you have selected is pressed down, get c0 is going to run every single frame while the button is held down. The reason that runs every frame has because we have it in our update method, which is called once per frame. And then the input.txt is gonna go up every time you like go out with a selected button. Anyways, this is the end of the quick introduction and installation portion of this course. So in the next video, we're gonna go ahead and actually get started with creating our 3D Pong clone here in Unity. So thanks for watching, and I'll see you in the next one. 7. Pong 1: Scene Setup: Hey everybody and welcome to the very first video of the Pong clone tutorial series, where we'll be creating a 3D clone of palm in Unity. Now in this portion of the course, not only will we be creating our punk loan in 3D, but I'll also be giving you some extra information along the way and kinda going over with you why we did what we did so that you can apply what you learn here in your own projects. So let's get started. Now in this video, we're going to do is create the scene for our game. So let's go ahead and go to New and create a brand new 3D project. On a call at Pong clone. Feel free to call it whatever you would like and start wherever you want. Then it creates. So once the project is open, we can go ahead and start creating our scene. So to do this, the first thing we're gonna do is go to the main camera. And I actually want to back it up a bit along the z-axis. There's something like negative 30. So I'm just going to change this over here under transform. Then I'm going to go down to my directional light and actually want to get rid of the rotation along the y-axis. Then let's change our background here to a solid black color. To do this, go to your main camera. Then in the inspector where it says Clear Flags, we want to change it from skybox to a solid color. And then just below that you'll see background. And if you click on this box here, you can change the color of that as well. And as you can see, the changes in real time, I'll just pick a solid black and then exit out of that. And we're good to go. Next, let's create the paddles for each of our players to control. So go up to GameObject. Good under 3D object and a cube. Now for our game here, let's go ahead and make our queue a red color. Today. Those inside of here, project folder under assets, just go ahead and right-click and go to Create. And we'll go down to material. We'll just call us red. Then go over to the inspector and where it says albedo, click on this box. Will change that to a red color. And you can change this to whatever you want. Then we'll just drag this onto the queue. Now you can see and change to the color red. And now if we adjust this, and we'll also change our cube in real time as well. Then let's go back to our cube. We're gonna name this player one. And you can do that right here at the top of the inspector. Then to get the shape we want, we're going to want to change the scale of this object. So along the y much translates to something like five. It's a little too big. Agenda 3, in the lung, the x will change it to 0.25. Right? Doesn't look too bad. And to make things a little easier on ourselves up here inside of your scene view, where are you going to see this? A blue cone along the z-axis. Let's go to the exact opposite of that. You can just click on this white count here. And I'll take you to this view. And now we're looking at it from a similar perspective. Through our main camera. Then move it along the x-axis to something like we'll try negative 20. And if you right-click on it and the hierarchy, you can go ahead and duplicate it. You can also copy and paste the exact same thing. We'll rename this to player two. And we'll have the opposite position along the x. So the positive 20. Now, obviously in this case we haven't really done a lot, but it's always a good idea to kinda save as you go, just in case you were to really mess something up or unity, British suddenly crash. You never want to lose your progress. So I always recommend saving often. So I'm gonna go to File Save. And it's always got the kinda just remember that shortcut of Control F. So that way you don't have to do this each and every time you can just quickly press flat. Next, let's create the bot. Will go to GameObject, 3D object, sphere. And what's given this a white color? One way we can do this is by going upward and materials here in the Inspector. And then where it says element 0 and default material, we can click on this little target here to the right. Let's go to Sprites Default. And as you can see, has a white color to it. Then let's set the positioning to 0. For the x, y, and z. There we go. Now we're going to need a boundary for the top and the bottom of our playing field. So I've got a GameObject 3D object. Cubed will give us the Sprites Default material as well. Let's let the positioning to 0. Then we'll change the scale along the x-axis to something like 30. All right, Let's try 50. Will move it up along the y-axis, right about here, which is about 10. So set that to 10 Exactly. We'll call this top boundary. We'll go ahead and duplicate it. Call us on bottom boundary. Will set its position to negative 10 along the y-axis. And as you can see, we're just about done. Next. Let's create two goals for player one and player two. And we can simply use the bottom boundary here. So let's go ahead and duplicate that. Will change the rotation along the z-axis to 90. So as you can see, that turned out vertically. And remember, you can change the transform, rotation and scale. Over here in the scene view. You have your different tools up here at the top for moving, rotation and scale. Let's set this to something like negative 35. We'll put the position along the y to the 0. Let's just duplicate it. Call this one player two goal. We'll give it a positive 35 for the exposition. All right, then let's scale down our sphere just a little bit. And we'll actually rename that to the ball. And let's scale it to something like 0.5. Make sure we do that uniformly. And lastly, we're going to need some UI to represent each player's score. Now we're not gonna go into too much detail on UI and the specific series. But hopefully you'll learn something nonetheless. And if this is your first time watching it for this project, you'll need to import the assumptions. You can download. The example is an extra if you want, but I'm just going to go ahead and close this. And as you can see, it created a canvas object for us over here in an event system along with the actual text. And what we're actually going to do is just go ahead and delete it, the text that it creates. Even just click on it and hit Delete on your keyboard. Then we'll go to the canvas. And what we wanna do, as in the inspector, go down to Canvas. And we're going to change the render mode from screen space overlay to world space. Then for the event camera below the set of none, we're going to click and drag in our main camera. And now we also have the ability to adjust the positioning and the width and height of our canvas. So I'm going to change the positioning to 0 on the x-ray and Lee and I might change the width to something like a 100 and same with the height. Then I'm going to right-click on our canvas. In the hierarchy here. Go down to UI, and then go to text, text much pro. And as you can see, they created some new texts for us, similar to what we had before. However, as you can tell, it's fairly large. So you're going to want to do is go over here to the font size, will change it to something like three. Then down below where it says alignment, we're actually going to center it. And below that, we're going to select the middle so that you can see that there's now centered on our screen here. And right here, just under the texts UI and the inspector, we can see where it says New. And we're gonna change that to the number 0. Then we're going to change the positioning. So let's go ahead and mess around with that a bit. So I'm right about here should be good. So we'll just call this negative 27 and positive seven. And we can rename this the same way we would any other object. Let's call this player one score. Then we'll create a duplicate of it. We'll call this one player to score will give us the opposite x positioning. So positive 27. And there you go. I'm actually going to know if that score just a little bit. So if our player one score, let's move it back a bit to you about negative 30. And we'll want to change the player 2 square to be symmetrical to that, so it gives it a positive 30. Then let's also move our paddles just a little bit as well. So go up here to player one. And I'll move this back a little bit. And if we check the size of our top boundary, it's at a scale of 50. So let's go ahead and change the position of our player one paddle here to about negative 24. So it's just a little before the edge of the boundary, which would roughly be at about negative 25. Obviously the scaling of her objects, so it's going to mess with it just a little bit. But we're not too worried about that. Then we'll change Player 2 to positive 24. And there we go. Anyways, that is it for this video. Once again, don't forget to save your project. And in the next video, we'll be working with player movement. So thanks for watching, and I'll see you in the next one. 8. Pong 2: Player Movement: Hey everybody and welcome to the second episode over the 3D Pong clone tutorial series. And this episode we're going to be adding in player movement. To the left. We're going to want to create a brand new C-sharp script. So and your assets folder, I can right-click. Let's go to Create. Let's go to folder. We'll just call this script. Then inside that folder, we're going to right-click again. Go to Create and go to C sharp script. Now creating a C sharp script in Unity. And it started like creating a class. And whatever you name, this is going to be the name I would like to show. You're gonna want to use the same naming conventions you normally would for a class and the C sharp. So for example, I'm going to call this player movement with no spaces and a capital P and M. Then we'll just go ahead and open this up areas. So once you've opened your new script, I should look something like this. And as you can see, our script started as a class with a name that we gave it. And you can always change those, but this is what comes up as default. Now as you can see, we have two starting unity method, one that runs at the beginning and one that runs every single frame. Now for this specific script, we're not going to need this was weighed start method. So you can go ahead and remove that. Then instead of a class, but outside of the update method, we're going to create two separate variables. One, the total is whether or not we are dealing with the first or the second player. And the second one that holds a speed value for our player movement. So let's go ahead and say Bool Player 1 equals true. And then under that, we're just going to say flow speed. And we're not going to initialize the value to this one. Next, a bubbler bull variable. What's doing? And close square bracket. And inside we're gonna say serialized field. Just like this. And I'll show you what this does here. So if we go ahead and save our script and go back to unity, then if we drag our script onto our player 1, then open up player one on the inspector. And you can see your script right here. And you can also see our player one variable right here as well. And it has a checkbox that lets us set the variable to either true or false, right here in the Inspector. Then I'm going to show you another way we can do this as well. So if we go back into our script with our float speed, if we make it public, save that, go back into Unity. You can see that our speed variable now also shows up in the inspector. So with the serialized field does, is allow us to get the same functionality without having to make our variables public. So let's go ahead and make this back to a private variable. And we'll put serialized field above in this one as well. And the reason we're doing it this way instead of making it public, because, because you never want to give anything more access than needed. As this will help prevent any human errors. Next is let's go down to our avoid update here. And we're going to create the player one controls. Just having a little comma here. The first thing we're gonna wanna do is create an if statement to check for player input. And pretty much anytime you're checking for player and you're going to want to put it inside out with the update method. So let's say if and then enter parentheses. We're going to say input with the capital I, die, got key with a capital G and K. And then in parentheses again, we're going to say key code with a capital K and C. And then as you can see, a whole list of options appears for us, showing us all the different key inputs we can get from the player. And feel free to take a look at this for yourself. Create. Now I'm just going to tell you the key is we're going to use. So say capital W. You can see it pops up right there. Then make sure you have a closed parenthesis. And we're going to say player 1 is equal to true. Okay? And the reason we're doing that, because these are Player one controls specifically. Now, instead of curly brackets, we're going to say transform, which is going to get the transform of the current object that the script is on. And we'll say translate with a capital T. And what this translate method does is it moves the transform and the direction and distance. However, the translation, the translation being a vector three value that we input here. So in parentheses, we're gonna say new factory 3 with a capital V and then parentheses. So we're going to say u 0 for the x comma speed comma 0. Then a close parentheses. And after that, we're going to say times time with a capital T. It's dot-dot-dot the time with another capital T. So let's go over this quick. We said that we want to take the object that our script is attached to and we want to get the transform of it. And as you can see when I that says the transform attached to the scheme object. Then we want to use this translate method to move the transform in the direction and distance over this vector three being the translation, which takes an x, y, and z. And then we multiplied this by Time.deltaTime. Now, for those of you who don't know what this is, Let's go over a quick. Now if you remember, our update method runs every single frame. So for example, if we wanted our character to have a movement speed of 50 units and we're running the game at 60 FPS, would actually move this many units each second. And thus might be okay if we got a constant 60 and if everyone who played our game also got a constant 60, but that's never going to be the case. So instead, what we want to do is multiply our speed value being five in this case by Time.deltaTime, which holds the amount of time between each frame. So for example, if we're using 1 second with a base measurement, and we divide it by 60. Assuming we were running at 60 FPS. This would be our Time.deltaTime value as the amount of time between each frame. Then when we multiply this by five, we get this value here. But we're running at 60 FPS, remember, so you actually want to multiply this by 60, which will give you the exact value of five. And this works no matter what your frame rate would be. So if we took 1 second again and we divide it by 120, and this time, our Time.deltaTime value would be this. If we are running at 120 FPS. Then we multiply this by our speed value times the amount of frames that were running the gay man. And we are back at five and once again. And this is why we always want the player movement by Time.deltaTime. Anyways, hopefully that makes sense to you. Let's go ahead and continue forward with our script. Next, let's go ahead and copy this if statement. Paste it down below. And this time we're going to change the capital W here and S. And this will be a downward movement. Then right before speed, we're just going to put a negative sign. So now instead of moving up along the y-axis, we're going to move down along the y-axis. Then let's create controls for player 2. Today, we can easily just copy everything we have above. Paste it down below. So at this time, instead of the W will say Up arrow with a capital U and a. Down here, we'll say down arrow. Then the last thing we have to do is change true to false. If it isn't Player 1, then we know it's Player 2. So go ahead and save your script. Then back in Unity, kind of player one, and then the Inspector, let's go ahead and change your speed to some filling 10. Then we're going to drag our script on to player 2 as well. Change the speed to ten again. And we're going to uncheck our player one bool, making it false. And we'll run our game. So now you should be able to move both of your paddles up and down with the up and down arrow key and the WNS key. However, as you can see, we have a problem here, which is that we just pass through objects. So make sure you stop your game by clicking on the plus sign up here. And solve this, what we're gonna do is add a rigid body to both our players and our boundaries. So you want to do is open up player one in the inspector. Go down to the bottom and click Add Component. And we're going to type rigid. In rigid body, it should pop up here. So go on and click on that. And now essentially add physics to our object. Then we're going to want to change a few options within it. First, let's uncheck this, Use Gravity bucks. Then in the constraints section, which you might need to open up my clicking on this arrow. We're going to freeze with position along the x and the z. And we're going to freeze the rotation along all three axes. And let's go ahead and do the same thing for player two. So uncheck the Use Gravity. Freeze the x and z position in phase rotation along x, y, and z. Then let's go to top boundary. Could add component. Rigid body again. Let's uncheck the Use Gravity. Simply check Is Kinematic. And if we wanted to, we can go ahead and freeze everything for the position and the rotation. We'll do the same parabolic boundary. So uncheck, Use Gravity, check as kinematic. And if you want it, you can check everything along the frees position and the free rotation. Then let's go ahead and hit play again. And as you can see, our petals cannot move through the boundaries, which is what we want. However, what you might notice is that while we're pushing up against the boundary or player kinda Bob's of that. And this might not be an issue for you, but it's something that personally bothered me. So why don't we go ahead and fix this? To solve this, we're going to do is click on our player one here in the hierarchy. And the instructor, we're going to check our y position, which right now is eight. And if we all go to the bottom at negative eight, and if I were to try holding down right now, we'll against this boundary, you can see that my position fluctuate. But when I let go, it goes back to exactly negative value. So what we're gonna do is actually lock both of our players within that range. So stop your game. Let's go back to our script and lower player K2 controls. We're going to create a position check. All we have to do for this, say if this transform position y is greater than eight, then we want to do the following. So we're going to say transform dot position equals new vector three. And then parentheses, we're going to say transform position x comma 0, comma transformed up position x0. Don't forget your semicolon at the end. Then let's cut and copy and paste this if statement down below. We'll change this to a negative 8. And then what we're actually going to do is change the 0 and this top one to a positive eight in the 0 and the bottom one to a negative eight. Then let's go back over this code together. We did is we create an if statement that says we want to take our objects transform. We want to get the position along the y-axis. We want to check if it's greater than eight. And so we're gonna take our transference position again, and we're going to set it equal to a new position being its current x, a y of a, and it's currently z. Okay? So right here we check the current. Why we've done here, we use the current x. We also use the currency. That's it because we didn't want to change anything along the z axis or the x-axis. We didn't want to change something along the y-axis. And down here, we basically just did the opposite. We said that if our y and we actually want to say is less than negative 8, and we want to shut it back to negative eight. And you can also see that the, this keyword is grayed out. And that's because we don't really need it. Let's just kind of explicitly styles for that. We're working with this object or the object for the script is attached to. And we could have done the same thing up here as well if we wanted to. But we can go ahead and remove this. As it is going to use the object it is attached to you by default. And we can go ahead and save our script. So back into Unity and hit Play. And now you can see that we solidly stop at both the bottom and the top boundary. So if for example we were at a and you can see that it will not let us go pass that. So there you have it. You've now added player movement for both player one, player two. And we can easily adjust the speed variable for each of them within our inspector. The other nice thing about having our variables in the inspector here is that while our game I was running and if we wanted to mess around with this variable. So let's say I change player one speed to 30. As soon as I stop running the game, that's gonna go back to whatever I had that set up before the game started running. And it is important to keep this in mind. So for one, you don't make too many changes and then lose your progress. And so you know that you can mess around with the values without actually affecting anything outside of that play session. Anyways, don't forget to save your progress. And that is it for this video. And the next video we're going to be adding in movement for our ball. So thanks for watching, and I'll see you in the next one. 9. Pong 3: Ball Movement: Hey everybody and welcome to the third episode of the 3D Pong clone tutorial series, unity. In this episode we're going to be adding to our ball. But before we do that, we're gonna go ahead and make a few changes to our scene here. So let's go to our player one goal and change the scale along the x-axis to a 100. And we'll do the same for Player tuple. Then let's go to our directional light and change the intensity to three. This will make both of our player paddles easier to see. Then let's also go up to our main camera and change the position along the x-axis to 0. Next, let's go ahead and make a few changes to our bot. So we'll go to bow and we'll go to Add Component. And we're going to add a rigid body. Then inside of here, we're going to change our Angular Drag to 0. And we're going to uncheck, Use Gravity. Also in the constraints section, we're going to freeze the position along the z axis and the rotation along all three. Then let's go ahead and create our script for the movement. And so, so in our scripts folder, I'm going to right-click and we're going to create NC Sharp script. Let's just call this ball. Then let's open it up. Now, once it's open, what we're going to do is go ahead and type out the whole script. Then we'll go back over it at the end. First off, above our void Start method, let's go ahead and create a few variables. First we're going to create a private flow speed. Then we're going to create a private vector 3 called direction. And another private vector 3, cold start position. Then what we wanna do is make just private flow available to us in the inspector. So if you remember, inside of square brackets, we're going to say simulation field with a capital Hashanah. Just like that. Next, down on our start method, which is called buffer. The first frame update. Well, we want to do is say start position equals transform dot position. Then below that, we're going to lunch with a capital L, open and close parentheses and a semicolon at the end. And some of you may recognize this as a call to a method. That's because it is those actually a call to a method that will be creating here very shortly. Next, down and void update, which if you remember, is called once per frame. We're going to say transform dot position plus direction times speed. And below that, we're going to create an if statement. And inside we're going to say input with a capital I, get key down with a capital G, K, and B. And in parentheses again, we're going to say keycode with a capital K and C space with a capital S. Then things had the body of her statement. We're going to just call the launch method again. Just like that. Now below this, we're gonna say debug with a capital D, dialogue with capital L and then parentheses phenotypes direction. Next, let's go ahead and create our launch method. So just below our update method, we're going to say private void. I'll spell it just like we did above. And then tied up here. We're gonna say transform position equals start the collision variable we typed earlier. Then below here we're going to say float x equals random range. And then parentheses, we're going to say 0 comma space too. We're just so excited that we're going to say is equal to 0 equals signs 1000. Question mark, negative one, colon one. We're gonna semicolon at the end. We'll go ahead and copy and paste this down below and change it from float x, y. And just below that, we're going to say it's direction equals new vector. And then parentheses, we're going to say x comma y. Outside of that, we're going to say diet normalized with a semicolon at the end. Then we're going to add another method which is already built into Unity called on collision enter. So we're going to save the late on collision enter with a capital O, C, and E. And then end parenthesis. We're going to say collision with a capital C space. Collision again with a lowercase c. Then entitled the body of that method. We're going to say contact point with a capital C and P. And we're gonna call it contact. And we're going to set that equal to collision. Die. Yet contact which had capital G and C parentheses, we're going to say 0 or the number 0 I should say. Then we're going to say elector three. Normal is equal to contact dot normal. Then below this we're going to save direction equals Vector3. Reflect. In parentheses. We're gonna say direction comma normal. So let's go ahead and go back over the US. So first we created a few variables. One thing, a private float cult speed that we've made available to us in the Inspector. Then we created TO private vector 3s, one called direction, which will be the direction that we want our ball to travel in. That are traveling in. And then another one called start position, which is going to hold the starting position of the object that we attach the script to being our ball. Then inside of our Start Method, which is only going to be called the 12 before the first frame update. We set start position equal to the object's current position. I saying transform that position. And if you remember, transform here gets the transform component attached to this game object. Thus game object being the object of the script is attached him. We could have also said this term pollution, but that isn't necessary. Then below this, we have a call to our launch method. Next and our update method, which is called once per frame. We said we're gonna take our object's position and add direction times speed. Speed thing this float value appear in direction of the vector 3 it that we created earlier, which doesn't yet have a value. Then we said, if the player presses space by using this get key down method inside of the input class, which is similar to get Qy, but whereas get C0 would run each frame that the key was held down. Get key down will only run once when the key is initially pressed. So we said when the Space key is pressed down, we want to run our launch method. And you'll see why we did this in a bit. Then we said debug dot log direction. And debug dot log. You can think of it as like an equivalent, the console dot write line in a console application. But this is for unity. So we basically said that we want to print direction to the console. Then we finally create our method called lunch, which takes our object's position and such that equal to question. Then we created two private floats being x and y. And we can actually go ahead and change these. In. These two integer variables will be set to either negative one or one, randomly. Accomplish that like so. So this random class is for generating random data. And as part of the Unity engine. Then this range method returns a random integer number between a minimum inclusive number and a maximum exclusive number. So because two is exclusive, it is not included here. So our range is only going to be 0 to one. And because it is an integer value, it can only be 0 or one. Then we said if this value here is equal to 0, then we want to set it to negative one. And if it is not equal to 0, then we're going to set it to one. And we did that by using the ternary operator. So essentially impacts and y will be set to negative one or one and should have a 5050 chance of either. Then we set vector 3 being direction equal to a new vector 3, which takes this x value. And this y value, then, because we didn't specify a z value and it's just going to default to 0. So direction will have an X and a Y, but no z value. Then we added this dot normalized, which returns this vector with a magnitude of one. And this was just going to help prevent any issues, at least for our specific case. But we're not gonna go into a whole lot more detail about that in order to keep things simple. For right now, just know that adding this dot normalized returns the vector with a magnitude of one. Then down here, we utilized another method that was already a part of the Unity, similar to this start and update methods. This one's called on collision enter. And if we mouse over it, you can see that on collision enter is called when this collider for a rigid body has begun touching another rigid body work later. So when the objects that are scripted attached to, if it has a rigid body or a collider and it collides with another one, then this method here is going to run. And this is something I'm sure a lot of you be using quite often and a lot of different game type. Then for perimeter and needs an instance of the collision class. And we went ahead and named our perimeter collision. If we mouse over the collision class here, it says that it describes a collision, which basically tells us that it has a lot of different things within it. To help describe the different parts of a collision. And feel free to look into those on your own time. If you're more interested and what options you have available to you within the Unity engine for working with collisions. Then inside of our method, we worked with a struct called contact point, which describes a contact point where the collision occurs. And this is somewhat similar collision except this one here for describing a contact point specifically. And we call this contact and we set it equal to collision that get contact at index 0. And the getContext method here, that's the contact point at the specified index. Now honestly, a lot of what we have here, especially in these three lines, is fairly complicated. And we're not going to dive into a whole lot of detail about it. If you want to learn more about collisions, contact points, or just some of these methods like contact or reflect. I highly encourage you to look it up on your own time and learn a little bit about it, even if it's just the basics. What it does, when can you use it and how to implement it into your own code. Just see you know, what's available to you and when you may or may not need it. And that goes for anything, especially when you guys are working on your own applications. I promise you professional programmers who've been working on things for 40, 50 years, even if it's all in the same language. They do not know every single method in class, et cetera, and available to them. What's way more important as a programmer is being able to utilize resources available to you whenever you come across a problem with a baby, books or the Internet, just find a solution implemented in your code and get it working. Then go back, maybe figure out a little bit about what it is, what options it gives you, and how you may or may not want to implement it in other applications. You don't always need to know every intricate detail of every little thing, especially if you may never use it again. And you'll hear this a lot from many professional programmers. Oftentimes being able to look up solutions to problems you have, being able to implement them in your own applications is vastly more important than knowing and memorizing every little thing. And it's honestly something you're going to be doing a lot of. So it's best to just accept that and move forward. But let's continue on here. So basically it just gets the contact point at the specified index. And we just went ahead and implement that index 0 for this value here. Then we created another vector 3 called normal, and we set it equal to contact being our contact point here. Normal, which is the normal of the contact point. Now, once again, if you don't know the normalised, feel free to look it up. But to give you a brief description, it's basically a line that is perpendicular to a given object. Then we wanted to set direction being the vector 3 we created equal to the vector three dots reflect, which just reflects a vector off of the plane defined by a normal In this takes an erection and normal. So basically, what this line here does is allow our object that we attach the script to, to reflect off of a surface. And like I said, you don't need to know all the little details of that trait now, just copy it into your code. And then if you feel it's going to be important to something you're going to work on in the future. Go back and look into it a bit. Anyways, go ahead and save what you have. And let's go back into unity. Then what we're gonna do is trigger scripts on turbo. And we're also going to add the console window here. So let's go up to Window here at the top. Who had under General could a console. And then you can just drag this wherever you want. And I'll put mine next to this project tab. And I did have a couple of you asked how I got this layout. And basically all you have to do discovery here to Window, go to layout. And I believe it's listed by 31. Then all I did was move things around a bit and scale him a little based on how I wanted it. Then let's go to our bile object. And for our script, we're going to change speed to 0.1 and we're good to go. So now if we hit Play, you can see that our ball moves in a ram direction, means that a consistent pace and it bounces off of objects just like we would expect it to. And if we hit space, we can reset the bow and send it off and went to four random directions. Also, balls direction is displayed right here in the console. And if for whatever reason your console looks like this, just click this collapsed button here at the top, and thus will make it so that duplicate text appears on the same line. And it's simply displays how many times it's been printed to the console. Anyways, that is it for this video. And the next video, we'll make it square ball resets when it hits either the player one or player Tikal will have the paddles recent with it. And we'll make it source scores for Player 1 and Player 2 adjust accordingly. So anyways, don't forget to save your progress. Thanks for watching and I'll see you in the next one. 10. Pong 4: Scoring & Reset: Hey everybody and welcome to the fourth episode, the 3D Pong clone tutorial series in unity. In this episode we're going to be making it. So on the bowhead, either the player one, player two goal, it will relaunch it. And we'll make sure that proper player gets a point and then it is displayed. And one of the score UIs here. Today. Let's start by going to player one goal. And inside the box collider component, we want to check is tricker. We want to do the same for Player tuple. Then we also want to give each goal a tag so that we know which one to ball hit. So inside the player one goal I put at the top it says peg. Click on this drop-down menu, go to Add Tag. Then we'll hit this plus sign here. And we're gonna say capital P, the number one goal with a capital G and save. And we're going to go ahead and add another tag called P2P goal. Just like that. Then we'll go over to player one goal will drop down and we'll select a P1 go. Gotta play or Tegel will talk to P to go. Then let's go to our ball movement script. Ahead and open that up. Then once those open, we're going to go ahead and rename our script to simply be 0. Up to do is highlight the class name here. Right-click Rename. Then we'll just type B capital B and hit Apply. Make sure you save. And this was automatically going to adjust when we go back into Unity as well. Then let's go ahead and add in all of our code. Pronoun just follow along and we'll go over it all at the end of the first, we're going to get rid of these two using systems, being using collections, collections dot generic. And instead we're going to say using system with a capital S. We're going to say TM grow just like that with a capital T, m n, p. And we're also going to say random with a capital R equals Unity engine. Random. This just means that when we use the random class in our code, that we want to use the random class from Unity engine and not system. We could also have just specified that we want to use the one from the Unity engine each time that we call the random class. But this will be easier since we don't play now using the one from system. Next, just blower variables here at the top. We're gonna say text Mesh Pro with a capital T and P. And then without any spaces still, we're gonna say capital U, capital G. Then we're going to call this score capital P and the number one. Just like that. Then just above us, we're going to say serialized field again, just like we did above. Copy and paste what we just did down below. And we're going to change this one to be score. Next, let's go down to the bottom of our script. We're going to create a new method. And here we're gonna save Private on Trigger Enter with a capital O, T AND Then in parentheses, we're gonna say collider with a capital C. And then other. Then inside of our method and we're going to create an if statement. So we're gonna say other dot is equal to. And then in quotation marks, we're going to save one. Just like we did when we created our tag. Make sure you have a capital P, the number one, and a capital G as well. Then your statement, we're going to call upon our launch method. Just like that. We're also going to debug score. Then below that, we're going to say int x equals dot parse. In parenthesis, we'll say score p2 dot-dot-dot. Then we're going to say x plus plus. Then we're going to say score p2 dot txt, convert with a capital C, two string with a capital T and S, and then parentheses or an essay. Then just below this, we're going to fade out. A tag is equal to p. Then we want to do is inside the body of that else-if statement, we're going to copy and paste what we have above. And change this to player one scored score PM10, score p1.x down here as well. All right, and lastly, I've been an update method. We're gonna go ahead and remove this debug dot log direction. Then go ahead and do what you have. And let's go for this quick. So basically we added in the system they're active as well as the TM Pro, which is for text Mesh Pro. And we said that when we use the random class, we want to use the one from Unity engine, not from system. And once again, we can specify that when we use random like show. So down here I could have said Unity engine random just like that. Then down below, we create a two references to objects for text by saying private text much pro you GUI. And we gave them a name score for player 11 for the square root or player two. And we made sure we can access these and the inspector with a serialized field. Then down below, similar to her on collision enter method, we created an On Trigger Enter method, which is also built into Unity. And if we mouse over it, you can see the On Trigger Enter is called the when the collider other enters the trigger. So when the object or script is attached to collides with another object that has trigger and its collider component, then the script will run. And we can get a reference to that glider right here. So if you mouse over a glider here, you can see it's a base class and hello colliders. As we're on collision enter method took a collision. This takes a client and we can reference it by using this name here. Being other. In this could be whatever you wanted it to be. Then we said if other dot tag, remember other as the object that we collided with. If the tag for the object as p1 goal, then we want to launch our ball. We want to say that player scored because it went in player one's goal. Then we created a new integer called x, and we set it equal to end up parse score p2 dot txt, essentially taking our player to score and converting it to an integer. And we did that by accessing our text much pro object here, which we referenced up above, and getting the text component from it. If we mouse over it, you can see it as a string. Then we added one to our integer by saying x plus plus. Then we took this x variable and put it back into score p2 dot text by saying that we wanted to convert our x back to a string. And we did that by using the convert toString method and then putting x as an argument. Then we did the same thing down below, except we checked with the tag was P2 goal. We're in our launch method, printed out that player one scored, etc. So let's go back into Unity. And you'll notice that our script name here changed the ball as well. Then if we go to our bot and go to our script and the inspector here, you can see that we still need to add in our text mesh objects. So we'll just open up the drop-down menu on our Canvas here. Treg and Player 1 score her score, P1. And drag and player 2 score Chris's score, repeat. Just like that. Then we can go ahead and run our game. And as you can see, the Florida missed the ball here, the proper player would score, and that would be displayed right here, as well as in the console. There we go. Then I just want to show you one last thing. So if we go to our player one goal and inside of our box collider component. Remember that we checked is triggered. When I went and to let you know, as if this was enabled, the collider is used for triggering events and is ignored by the physics engine. And what that means for us and for our bot connects with any objects that have a box collider. But as trigger as enabled, it will not be considered a collision. And I can show you this like so. So back in our on collision enter method, I simply added and this debug dot log collision. Then if I go back to Unity here and hit Play, you can see that when our ball hits a wall or a player, it says collision. But if it hits one of our player one or player two goals, it does not. And that is because as triggers enabled on both the player one and player 2 goal, anyways, don't forget to save what you have. But does it for this video. And the next video, we're going to be adding in a game over and, or a windscreen. So thanks for watching and I'll see you in the next one. 11. Pong 5: Game Over: Hey everybody, and welcome to the fifth episode with a 3D Pong clone tutorial series in Unity. What we'll be doing in this episode is creating a game over screen. It will tell us which player has won and allow us to reset our gain. And will also be cleaning up some of our previous code as well. So let's get started. First, we're going to create a brand new C-sharp script. And we're going to call this score. Then what I'd like for you to do is open up both your bot script and your score script. And what we're going to be doing is actually taking the score code from our bot script and moving it over to and we'll clean it up a bit as well. To do this, we're first going to copy all of the using directives from our bot script and paste them into our score script, replacing the ones that were previously there. And we're gonna go ahead and remove this using random directive here. Then back in our ball script, we're also going to remove the using Tim Pro directly. Then we're going to cut our text much pro variables and paste them into our scores for just inside of the square class. Then back in our scripts that we're going to scroll down On Trigger Enter method. And we're going to cut the entire method and paste it into our score screen. And we'll do this just below our void update method. Then we have one last thing to do back in our postscript. And all we need to do is go over to our launch method and change it from private to public. Then go ahead and save it, and go back over to your score script. Now, what we're gonna do is create a reference to our bot script so that we can use this lunch method. So below our text Mesh pro variables, I'm going to say private. With a capital B being the name of the script we want to get access to and call it fall with a lowercase b and put a semicolon at the end. Then and avoid start method, we're going to save ball equals get component with the capital GNC. And then the less than symbol. And we'll say ball with a capital B thing, the name of her script on, again, the greater than symbol, open and close parentheses, and a semicolon at the end. So basically, we created a private variable of our class. We set L equal to our ball script. I saying Get Component. And then the name of the script that we want to get. And we'll be able to get this by setting our score script on the same object as our ball script. If it was on another object, we'd have to create a reference to that object first and then get the component from that object. But this way will work just fine and our case. Next, let's scroll down to our Voice Trigger Enter method. And inside of our if statement where we call upon our launch method, we need to say where this was coming Chrome. So we'll say ball. Orange, just like that. And because Paul is equal to our ball script, I don't know where this method comes from. Next, let's change up some of the code and our f statement. So in our last video, what we did is we actually got the integer value out of the text from our UI for our player to score. And we put this value inside of an integer called x. Then we added one to x when player two scored. And finally we took a text and our UI and set it equal to x. And to be honest with you, I'm not really sure why I did this. So we're just going to fix it. So instead what we're gonna do is create two scored and Fables. So backup here at the top. Under our variable. We're simply going to say int score one equals 0. And below that we'll say score to 0. Then let's scroll back down toward the if statement. And we'll remove this int x equals in dot parse line, as well as this x plus plus lines. And instead, we'll simply say score a two plus plus. Then instead of saying convert to string x will simply say convert to string score of two. Just like that. Then we can go ahead and copy everything in this if statement in place with down below and our else-if statement. And we'll change that from debug dot log player two and player one scored. Score one plus, plus score p1.x and convert the string score one. Next, we'll make it so we have an actual wind condition. To do this, we'll simply create an if statement inside of our update method. So say F score one is equal to 10. Or and I remember the STT where you just need to vertical line click this. Score two is equal to 10. Then we want to do the following. And we'll actually come back to this a bit later. So go ahead and save your script, will go back into Unity. And what we're gonna do is drag our score script on turbo object. Then open up our file object in the inspector will scroll down to our script here. And as you can see, we need a reference or a score, p1 and p2. So inside of the canvas, which like player one score and we're gonna score P1. And player 2 score, test score P2. Just like that. Then we can hit Play to test that again. And as you can see, it works the same way that it did before. The only difference being that we split up our scripts so they each have a more specific function. Next, we'll create our game over screen. But before we do this, what we're gonna do is go to File here at the top. Go down to Build Settings and Add Open scenes. And our sample scene should be added right there. Also take note of the name of our scene, which a sample scene with two capital Ss and no spaces in between then will exit out of us, will go to file again. And new scene. It make sure you save your sample scene. Then what we're gonna do is go to the main camera. Will change it from skybox, solid color. And we'll change the background color here to black or whatever color you want. Then we'll go to GameObject. Go down to UI. You've got a text, her tucks much pro. Then I'm going to fix my scene view here. Next, if we click on our Canvas, we want to change the UI scale mode from constant pixel size to scale a screen signs. And as you can see, this may have offset your text here. So we'll go to our text component and just drag it into the Canvas. Then we're actually going to change the position x of our texts to be 0. Then we'll adjust the height to something like 120. Then instead of a new text, I'm going to say player space, the number one, space one. I'll put an exclamation at the end, just like that. Then affects on the same line. We wrote it down here to the font size and check out a size, which as you can see here, auto size of the text to fit the available space. Then to make this bigger, we're going to go up here to scale and change it along the x, y, and z to two on all accesses. And we'll go ahead and move it down a bit to something like a 100. Along the y axis there. Next to a creative button so that we can restart our game. So I'll go to GameObject UI, button text much Pro will set the position along the x to 0. And along the y will change it to something like 0. Then if you open up the drop down menu on our button here in the hierarchy, you can click on the text component of it. And down here where it says button, and the text will change this to restart. All right, the next thing we're gonna do is create an empty game object. So we'll right-click here in the hierarchy and go to Create Empty. And we can just leave this as us then to create a new C Sharp script for restarting or game. So in our scripts folder, I will create a new script. And we'll call this restart. Then go ahead and open that up. Here at the top, we're going to add a new using directive. So we're gonna do and say Unity engine, just like it shows above. So capital U and E, and then dot seen Management with a capital S and M. Just like that. Then down below our update method. We're going to create a new method. Right here. We're going to say public void. And we'll call this restart game. Then inside of our method, we're going to say scene manager with a capital S and a ham, with a capital L and S and M parenthesis. And also inside of quotation marks, we're going to put the name of the scene that we want to load. So if you remember the name of our original scene as code samples in. So we'll say sample scene with two capital Ss and no spaces. And this has to be exact, otherwise it will not work. Then we can go ahead and hit Save. Go back into unity. Then we'll drag our restart script on to our empty game object. Next we want to go to our button here and go all the way to the bottom racing this onClick method call. And we want to hit this Plus sign here to add some functionality, or whatever functionality we put here will run when our button is clicked. Then where it says None object, we want to drag in our gameObject being the empty object we created. Then we'll click where it says no function. Go down to restart, which is actually the name of the class we just created. And we'll look for the method that we just created as well, being restart game and click on that. So I run it there now, just got a file here at the top. And go to Save As and save our scene. Then you'll want to go to your scenes folder. And for the filename, you'll want to put the name of the scene. And we're going to call this game over scene with a capital G, o and S. One with a capital P and the number one. Then we'll hit Save. Then what we're gonna do is create another scene just like this for player two. And the easiest way to do this would be like so. So inside of our canvas, and we'll go to our text here that says Player 11. And we'll change it to play or 21. Then we're just going to go to File, Save As and our scenes folder again. And we'll click on the schema Racine P1 will change it to P2 and hit Save. Then what we wanna do, just go to File, Build Settings and Add Open scene. And as you can see, we now have our sample scene here. And our Gamma overseen, the h02. And we're doing this so that we can access them properly and our scripts. And walks out of this. We've got a file, open scene, kinda scenes and got a gamma or seen p1. Then we'll go to File again, Build Settings and Add opening scenes. Then we can close this out again. We've got a file again, open scene and cosines and open our sample scene. Now let's go back to our score script. And instead of our update method where we created this if statement, that checks of score one is equal to 10, or a score of two is equal to ten. We're going to add some code. But just before doing so, we're going to scroll up to the top and add the Unity engine chain manager direct node like we did before. So I'll say using Unity engine management, put a semicolon at the end. We'll scroll down to our else statement. Then inside a print f statement, we're going to check which one of these was true. So we'll say F, score one and is equal to 10. Then we want to do a hollowing. And right inside of here, we're going to say manager with a capital S and M login with a capital L and S, just like before. Then in parentheses and in quotation marks, we'll say Game Over scene one. And the exact same format of our scene. Then we're going to copy this statement and paste it down below. And we'll change it from l to l. Will change it from score one to score two. And we'll change it from GameOver seen p1 to game over scene P2. Then let's quickly go over any new code that you may not have seen before. So the scene manager dot load seam line, simply load to the scene that you insert between these quotation marks. And in order to access the scene manager class and use this load seen method, we had to use this directive that we added here at the top being the Unity engine management. Then make sure you save all of your scripts, will go back into Unity and hit Play. Then I'm just going to skip ahead until one of the players is near ten. Alright? So much my player two hits 10 points. It says player 21. And I can click Restart. And a researcher again. Anyways, don't forget to save your project. And that is it for this video. And the next video, we'll finally be adding in some sound that will play when our ball hits an object. So thanks for watching, and I'll see you in the next one. 12. Pong 6: Sound Effects: Hey everybody, and welcome to the sixth episode of the 3D Pong clone tutorial series and unity. In this episode, we're going to be adding in a couple of sound effects for our game. The first one being for when our ball hits an object. And the second one being for when either player one or player two scores a goal. So the first thing we're gonna do is download both of these sound effects. And we're going to be getting them from a place called Zap slot.com, which is a place where you can get free sound effects and music. Don't worry, it's completely free. All you have to do is make an account and you'll be able to download the MP3 files. And I'll be putting both of these links instead of a text file. But you can find under projects and resources. So what we wanna do is open up both links. Then you want to click where it says MP3 and hit download mp3. Now real quick, I'm not affiliated with the site. And anyway, and if you guys want to use a another site to get your sounds, that is completely okay. So you're going to need to do the same thing for the other side of the HUC. And once again, feel free to use whatever sound G1. It's not gonna make any difference in the steps required. Then back in Unity and our assets folder, I'm gonna go ahead and create a brand new folder. And I'm just going to call this sounds. Then you'll want to open up the folder that has the two sound effects that you just downloaded from most to you. This will probably be in your downloads folder. Then we're simply going to click and drag them into our Sounds folder. Next, we're going to create a couple of empty objects to hold each one of our sound files. So we'll go ahead and right-click on the hierarchy and you gotta create empty. Then I'm just going to call this first one collision effect. Then we're going to create another empty object and then call this goal effect. Then on our ball collision object, I'm going to go to Add Component. Then I'm going to type audio. Go to Audio Source. Then we're going to uncheck this plan awake so that it doesn't play immediately when we start our game. Then this right sound for me, as many ping-pong ball times 4 bounce sound. And that's the one I'm going to use for our goal. And this other one I'm going to use for when the ball hits an object. So I've got a bug collision effect. Then I'll drag this sound on the left over to my audio clip here inside the audio source. Then we're gonna do the same thing for our goal effect, except we're going to use the other sound. So I'm going to Add Component Audio Source. We'll drag our sound done and I'll uncheck plan away. Then what we're gonna do is make both of these objects a child, our ball object. So all we have to do is click and drag them on tarball object like so. Next we're going to add in the code for playing our sound effects. So we'll go to our scripts and we're going to open both our bot script and our score script. So in our ball script, we're going to be creating a reference to our bulk collision effect object and the audio source within it. So up here at the top, we're going to say private gameObject with a capital G and L. And we'll call this collision effect object. And we want this to be available in the inspector. So right above it, we're gonna say careless field, just like we did up here above for our speed variable. So I'll just copy and paste those. Then below this line here, we're going to save private audio source, the capital a and x. And we'll call this collision of H2. Then you need a set our audio source here equal to the audio source component N plus object. So Dan and extract method here right at the beginning, we're going to say collision effect equals collision effect object dot-dot-dot component with a capital G and C. The less than symbol audio source with a capital a and the greater than symbol opening close parentheses and a semicolon at the end. And lastly, for the script, we need to add in the code for actually playing the sound. So for this one here, we're gonna go down to her on collision enter method. And below our debug dot log line, we're going to say collision effect. Play with a capital P and open and close parentheses and a semicolon at the end. Then we can go ahead and save. So what this method here does is it plays with the sound attach to our audio source component. Then we're gonna go over to our score script and essentially do the exact same thing, but for other sound effects. So at the top here, we'll say serialized field, inside of square brackets. Then we'll say private gameObject. And we'll call this one goal effect object. Then down below this, we'll say private audio source. We'll call this one goal effect. Just like that. Then once again, we're going to set our audio source equal to the audio source component from this object. So at the beginning of our start method again, we'll say Go effect equals goal effect objects dot.com. And then said less than and greater than symbol. And we'll say audio source. Open and close parentheses. And a semicolon at the end tend to play the sound. We're gonna go all the way down to our On Trigger Enter method. And inside the method and outside of both of the f statements. As we don't really care which IF statement runs. We'll just say cool effect that let's say capital P, open and close parentheses and a semicolon at the end. We'll hit Save. Then we'll go back to Unity. And real quick, we're just gonna take a quick look at our audio source component here. So this has a bunch of different options which I encourage you to look over, such as trim using looping, playing on awake. You can adjust the priority I with a sound. You can adjust the volume of pitch, etc. Then lastly, all we needed a set our references. So on our ball object, we'll go down to our bot script. And for our collision effect object, we'll drag in our bulk collision effect object here. And for go Effect object will draw again our goal effect object here. Then before we play our game, there's one last thing I wanted to mention. So when you are using audio sources, you also need an audio listener to actually pick up the sound. And by default, your main camera has an audio listener on it. Anyways, let's go ahead and hit play. And now, as you can tell, our ball creates a sound anytime that I collides with an object. If a player scores a goal. So there you go. Anyways, that is it for this video. In the next video, we're going to be creating a positive function for our game. Yeah, I know it's Pong and the odds of you guys needing to pause your game, pretty much slim to none. But I thought it'd be a good time to show you guys how to do it anyways. So make sure you say what you have. Thanks for watching, and I'll see you in the next one. 13. Pong 7: Pause Game: Hey everybody, and welcome to the seventh episode of the 3D Pong clone tutorial series in unity. And thus episode we'll be adding in a pause function for our game. Now, I know it's only Pong and the odds of you guys ever needing a pause function in your game? Pretty much some didn't. But hey, you never know. So let's get started. The first thing we need to do is actually fix something and our ball script. So let's go ahead and open that up. Then instead of update method here, where we have this line of code for our movement, actually need to add something. So right after the word speed here, we're going to say times. I'm dot delta time. This way, anyone who plays her game will have consistent movement for it, the ball. This was something I forgot that I had an earlier. So I thought we'd go back and fix it. Then go and save your script, will go back into unity. Then let's go to our ball here in the hierarchy. And we're going to change the speed to something like 20. Then let's go ahead and see how that runs. And that seems pretty good to me. So I'm gonna go ahead and leave it at 20, but feel free to adjust that to whatever you'd like. Then let's go ahead and create the script for pausing our game. So in our scripts folder, we'll just create a new script. We'll call this pause. Let's go ahead and open that up. Then the first thing we're gonna do now is go ahead and get rid of the start method here, as we won't be needing it. And we're going to create a bull variable. So we'll say, we're going to call this as paused and set it equal to false. Then in our update method, we're going to check if the player presses the peaky. So we'll say if input, remember that's what the capital I got key down with a capital G candy. Then in parentheses, we're gonna say key code with a capital K and P, capital P. Then inside of our if statement, we're simply going to say is paused. Meaning fs pause is true. Then we want to do the following. We want to say time with a capital T timescale with a capital F equals one. Just like that. Then the lower IF statement we're going to say else. Time dot timescale, just like we did above 0. So let's go over this code. So first, we just created a simple Boole called as paused and set it equal to false. Because we don't want our game three paused at the start. Then we said, if the peaky as press down, we want to do the following. We want to check if our game is paused. And if so, we want to set the timescale to 1.5. And if our game not paused, then we want to set the timescale to 0. And if we look at what this float here is, the scale at which time passes and that it can be used for things like slow motion effects. Now, timed that timescale only affects specific things. And I highly encourage you to look into these when you get the champ. For example, it's not going to pause our update method, which will allow us to still get this input here. Also, just for reference, one in this case means essentially a 100 percent. So it's going to run normally. And 0 is 0%. So it's not going to run at all. Meaning, for example, if we change this one up here to 0.5 or game would essentially run at half speed. Then we're just about done. We're just going to do one last thing. So instead of each of these, we need to change R is paused. Variable would be the opposite of what it currently was. So in our if statement will say is paused equals false. And down here, say, is paused equals true. Just like go this way. And if our game is currently paused, we will un-pause it as paused equal to false. And otherwise, if our game is not paused, We will pause the game and then set this equal to true. And we're all done. So unsafe will go back into unity. Then we'll drag our postscript onto our main camera and hit play. And as you can see, if I hit the peaky, our game pauses. And if I hit it again, it will un-pause. Just like that. Also, you won't be able to move her characters up and down while the game is paused. Because they are affected by Time.deltaTime, which is one of the things affected by the time dot timescale variable. Anyways, that is it for this video. And the next video, we'll be creating a shareable version of our game so that we can share it with others. So we should have said what you have. Thanks for watching and I'll see you in the next one. 14. Pong 8: Final Build & Exit Application: Hey everybody, and welcome to the eighth and final episode of the 3D punk clone tutorial series and unity. In this episode, we're going to be creating a shareable version of our game. And luckily, this was actually pretty easy to do in Unity. But before we create our shareable build, we're actually going to make it so that the player can actually close out the application. As up until this point, we've just been using this Play button to both start and end our game. And to make this process easier on ourselves, we're simply going to use our postscript from before. So go ahead and open that up. Then let's go ahead and copy our if statement and paste it down below. Just like that. Then let's remove all of the code inside of our new IF statement. Then instead of checking for when the player presses the peaky, let's check for when they press the Escape key. And to do this, we can simply type out the word escaped with a capital E. So just like that. Then inside of our if statement, we're simply going to say application with a capital a, with a capital Q. Then open and close parentheses and a semicolon at the end. And as you can see when we mouse over this method here, it says, let a quips the player application. Now one thing to know is that this method here is completely ignore it inside of the Unity editor. Meaning we won't be able to test it inside of the editor like we can with the rest of our code. But luckily, it's not a whole lot of code and it's pretty straightforward. Basically, we use this if statement and our input.txt key down to check for when the Escape key was pressed. Then inside of the if statement, we call upon this quit method, which was part of the application class, allowing the player or ourselves to close out of the application at anytime. And that's all there is to it. So go ahead and save your script. We'll go back to the editor and create our standalone shareable belt. So all we have to do is go to File here at the top. Good under Build Settings. Then, because we made our game for PC, we can just leave it on the PC platform. We want to make sure that all of our scenes here are checkmarked. Then down here, we don't need to change anything because everything is already good to go. Then I have to do is click on Build. Then you don't want to open up the folder that you want to build the schema and two, and hit Select Folder. Wait for it to finish building. Then once it's done, down here at the bottom, it should say build completed, and you're all good to go. So now if we open up that folder that we just built our game and two, it should look something like this. And for those of you who've downloaded a Unity game, say off edge dot IO or something like that, that should look pretty familiar to you. And that's because it's already the start sharing with others. Well, you have to do is take the folder that we selected when we created the build of our game and share it with whomever you'd like. So there you go. You've now created a palm clone and unity. And for those of you who have followed the series from start to finish, and also went through my C-sharp course for beginners. You are now ready to go out and start creating your very own games in Unity. And I promise you that the best thing you can do for yourself if you're wanting to become an indie game developer, is to just start creating games. Just remember to keep the scope low at first. For example, make a single-player game and come up with an idea that you failed, that you can finish within a reasonable amount of time, that be a month or two months, or maybe even six. And don't get discouraged. But I promise you it's probably gonna take you at least twice as long as you think it will. But don't worry if you run into any snags or anything that you don't know how to do. Look it up. And getting the hands-on experience was going to boost your learning immensely. And I'm willing to bet that you actually know a lot more than you think you do and can get a lot more done with what you already know. Don't want you probably feel you can right now. So like I said, just come up with an idea that you feel that you can finish in a short amount of time and just get started. And you can even focus on just the programming side, like we did here, where we use simple shapes as placeholders. And then you can go out and find an artists online who is willing to help you with your project just so they can get something under their belt as well. Anyways, best of luck to all of you. And as always, thanks for watching. 15. FAQ: Lighting: In this video, I'm quickly going to go over with you a few ways that we can edit and adjust the lighting in our scene. And by the end of this video, your lighting will look the exact same way that minded and the intro for this class. So the first thing we're gonna do is go to our player one here. Then under the Mesh Renderer and under lighting, we're going to uncheck, receive shadows. Then we'll do the same for Player 2. Next, we're going to create an empty game object and call it light. And we'll set its position 2 000 000. Keep in mind that this doesn't really make a difference. It's just going to help clean some stuff up when we add child objects to this object. Next, we're gonna take a directional light and make it a child of her lights object. Then instead of directional light, what's called this directional light forward. Let's remove the rotation along the x axis as well. So instead of 50 will change it to 0. Next, let's go ahead and duplicate this layer a couple of times. We'll change our second one here, Ted directional light left. And our third 12 directional light, right. And as you can see, everything is currently white in our scene. And that's because the intensity on our lights as too high. Because if you remember in a previous video, we changed our intensity to three. What shameless back to the default of fun for all of our links. And as you can see, it's starting to look better, but it's still pretty bright. And that's because right now all of our lights are facing the same exact direction. So what we need to do is go to a directional light left here and change your rotation along the y-axis. And negative 90. As you can see, that it's now facing to the left. Then we'll do the opposite for a directional light, right? So change that to positive 90. There we go. And feel free to mess around with the different lighting settings to figure out all the different things you can do here in unity. And by the way, reason we added all of this to this empty game object to call lights. It's just to help us sort everything here in our hierarchy. Because now we can simply minimize it like this. And we have all of our lights in one spot. And now down here in our game view, as you can see compared to before, we can now see the innermost sides of our paddles. So there you go. Anyways, hope you enjoyed the video and as always, thanks for watching.