Make a 2D Platformer Video Game with Unity and PlayMaker (no coding required) [Part 3] | Brandon Wu | Skillshare

Playback Speed

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

Make a 2D Platformer Video Game with Unity and PlayMaker (no coding required) [Part 3]

teacher avatar Brandon Wu, Founder of Studio Pepwuper - a Game Studio

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

7 Lessons (59m)
    • 1. Introduction

    • 2. 25 Camera Follow Intro and Simple Setup

    • 3. 26 Camera Follow FSM Intro

    • 4. 27 Camera Follow Setup

    • 5. 28 Parallaxing

    • 6. 29 Collect Coins

    • 7. 30 Collect Coins GUI

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

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.





About This Class


Note: This is part 3 in the series: Make a 2D Platformer Video Game with Unity and PlayMaker (no coding required). Find part 1 here, part 2 here and part 4 here

Teacher: @theBrandonWu

Now that Unity supports 2D games, we can make a game in one of my favorite genres – a 2D platformer! (Think Super Mario Bros. on the NES... ah those were the days!)

In this series, which is the perfect follow up from class 1 (I recommend you take at least the first 2 weeks of class 1), we’ll go over the basics of Unity 2D, sprites and animations, 2D physics, and all the controls you need to get a 2D platformer going.

And all of this without writing a line of code, thanks to the power of the awesome Unity plugin: PlayMaker!

The class at a glance:

  • Bite-sized, Easy to Follow Video Lessons
  • Self-Paced Online Class with Fellow Student and Teacher Support

Here’s what you’ll learn in this series (it's divided into 4 parts):

  • Part 1: Introduction to 2D space in Unity
  • Part 2: Introduction to our 2D platformed game and setting up player character
  • Part 3: Dealing with Camera – the easy setup vs the complex setup
  • Part 4: Setting up Enemies, HP, and Attack before we wrap up!

Who is This Class for?

This class is for beginners with a basic understanding of Unity and PlayMaker. If you’ve never used Unity or PlayMaker, you can start with this class first. Both courses are adult and kid-friendly! :)

What You Will Need

  • 7-10 hours of free time as we dive into the process of 2D game development. 
  • A modern PC / Mac with 3D graphic compatibility (if you bought your computer in the past 5 years, you should be good to go.)
  • A download and installation of the Unity3D game engine Don’t worry about the seemingly complicated interface, we will go over it in the class – piece of cake!

About Playmaker

  • Students will be provided a special student version of the popular Unity 3D ToolPlayMaker. This is the tool that enables us to create games without writing code. Thanks to Hutong Games, this special student version will include ALL actions in the tool (note: student version not for commercial use).
  • Commercial version of PlayMaker – we strongly recommend buying a license for PlayMaker. Although you can use the student version of PlayMaker for the class, the class is really designed with a commercial version and it allows the use of additional free add-ons and tools to make your game development life easier. It is one of our favorite #gamedev tools ever!

What Students are Saying About Brandon’s Classes

“Exactly what I needed to begin my journey into game development. I will DEFINITELY take ANY other classes taught by Brandon Wu! Thank you Brandon!!”
– Nicholas Mitchell


“Time and money well spent. I have no coding experience at all but thanks to this class I feel much more confident about game dev process. Thanks for this amazing class!”
– Sung Kim (Animator)


“Brandon Wu’s class was simply the most richest online educational experience I’ve ever had! So much content, so much detail, and so so much fun! I would recommend this class to anyone who has even the slightest of interest in how games are made. I’ve paid 50 times more for an online class, and this has been the best!”
– Brian Anderson


“Great class!! Enjoyed making the projects. The amount of information covered in 4 weeks, was just right. Instructor was knowledgeable and supportive.”
– Greg D.

Meet Your Teacher

Teacher Profile Image

Brandon Wu

Founder of Studio Pepwuper - a Game Studio


Previously a strategist at Sony and a developer at Electronic Arts, Brandon is the founder of a game production company and co-founder of an augmented reality startup. He founded and grew a Seattle game developer community to 2000+ members and is a bestselling author on Brandon has been a mentor and a speaker for Cambridge University, Anglia Ruskin University, Microsoft, Cambridge University Press and many other organisations.

Student Endorsements:

Company: Studio Pepwuper: Twitter: See full profile

Class Ratings

Expectations Met?
  • 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.


1. Introduction: welcome to part three of our two game tutorials for Unity and Plain. In the previous two parts we've looked at, he spread she's animations two D graphics inside Unity, which is 30 engine, but it supports two D games as well. Now we also looked at player. Contreras would look that physics inside to the world. And in this part we are going to look at camera. Camera is a bit different into D. Now we're going to dive into how we control the camera, how we get the camera to follow characters. How do we do parallax in into the games as well, at some basics on some coin collection mechanisms on the u I. So I hope enjoy this part and I will see you in the courts. 2. 25 Camera Follow Intro and Simple Setup: now, before we continue to build out our level, I want Teoh set up the camera so that it follows the player. So basically, whenever the players moving level right, we want a camera to follow this character so the character doesn't get out of the screen. And there are I'm going to show you two ways of doing this. One is a sort of straightforward, simple method, and basically, we're just gonna have the camera copy the why sorry. Copy the exposition off the player and on court today, and that's gonna be a simple creek set up, the other set up. It's going to be a little bit more complex, and if you don't feel comfortable with some of the ways, is going to set up. Don't feel frustrated. It's It's a little bit complicated, but we will go through the video a few times and hopefully we'll be able to understand it. If not, the simple method work perfectly fine as well for your game. Okay, so let's start with the simple follow method and click on that's click on add component to the camera. That's one ad, a state machine, and we're just gonna have one state called followed. And all we need to do It's very simple. We want to get the position of the character and then copy that to the camera position. So let's go to variables. And that's just define any variable. I'm gonna call this player Position X. So that's where I'm gonna hold the X value of the player position. So come back to the state, their action browser, and we want to get position. So that's gonna be under the transform category where you can like what I just did. You can type in the search here, okay. And, uh, game object. We want a special specific game object, which is the player came objects. I'm going to drink that here, and I'm going to sign the X value to the exposition acts expose axe Miracle. I don't do this. Every friend and next thing I want to set position again. It's under transform category, double click on it to had this to estate and we want to set the position of the owner, which is the camera, and we want to use player position X. Make sure that this matches was space here, which is the world space and where's the ones? Do it? Every frame and that stood in the light late update. So basically, this will update the position after everything. I was stunned in update safe, and uh, let's play it. You could see that. What? There's simple state machines will dio for the camera. So now when I moved the character around, the camera will follow it so you can use this to quickly create to get started with creating the level, because now we can have a much bigger level and the characters going to stay in the screen . That's good. 3. 26 Camera Follow FSM Intro: now the second option for setting up the camera as to have the camera start following the character when the cara goes at the edge of the screen and let me just show you what I mean by that. So I have set up in the scene, and this is the camera control on it. I can see that when the characters moving at the edge edge of the screen, the camera starts scrolling with it, so that's what we're going to do. So let's take a quick look at how this state is set up for the camera to follow the player that we want it. First, we have our innit scene where we go and find the player object and put it in invariable so we can use it later on Next. We want to check which direction this character is moving. Now there are a few different ways you can do it. You can check and see if the left key over the right there okay is being pressed, or you can do what we're doing here, where we're checking the velocity on the X axis to see if it's a positive number or negative number. So that would there? Let's know that which direction this character is moving that for right now? The reason why I wanted to go was I wanted to check the velocity instead of the key press is because, let's say down the line we have enemies or other things going on in the game. There might be situations where the character might be moving, but there's no key being pressed right. So let's say if an enemy attacks a player and then the character sort of gets knocked back a few units then even though the player is not president occasion to character mice to be moving. And we want the camera to be able to know that movement, this route. So here in the state were simply getting the velocity off the player object in a variable player of lost e eggs, and we're gonna check the sign of this float using the floats signed test. And if it's positives, we're gonna go to the next state, which is moving right to state. So this is what we will do if the character is moving that direction. And obviously, if the last year's negative, that means the character is moving towards the left, and we're gonna go to a different state. Okay, let's say if the player is moving right, So we're gonna go to this state here, and from here we want to do is detecting if the player is touching the edge of the screen and we're gonna define how big of a monitor and we want to leave for the player to move right. So here the first thing we do is we get the position of the player, put it in the player pause, x variable. And then we want to use this action called World to Screen Point, which basically translates the world position off the player to the screen position. Now, if he don't remember what the differences are, the screen position is the position an object has in on the screen. So it's only got the ax access and the Y axis here. The World position Harbor, on the other hand, is the position off the object in the world space, which in this case there is the transform position here. Actually, in any case, it's the transform position in the engine three D engine. So everything in the world is as a three D position on the screen. It's on. Lee got to access, right? So what? These actions So so in the action browser, you can actually find a bunch of actions that deals was translating between a screen space and their world space. So here, what we want to do is we want to translate, want to convert screens, the world space, the world acts, which is what we got from the previous action to its corresponding screen space and the reason why we want to do that. It's because we want this to work. Record this of the screen size. So let's say I have the screen size here. There's 10 24 by 7 68 When I changed that aspect ratio, you can see that the game is gonna have a different looked hurt. So if I used the world space for the for detecting the edge, it might not give me the result that I wanted one. The screen is on a different device Now. We want to make sure that normal not know, normalize has checked it. So that means when this is checked than the the coordinates for the accidents are going to be between zero and one, which is very handy carries in the next action. We're going to compare the screen space, the screen position to point Aid, which is basically saying we're gonna have 20% of margin here. And when the correct it goes up to this 20% this 80% position 800.82 this is zero. This is one on the X axis. Then we're going to start following the character, right? So that's what that's doing here. We compare their screen position on the X axis, and if it's greater than point A. If it's if the character is moving further than 80% of this line here, then we're gonna go to the at Edge transition and it's gonna go to the next state. Okay, so they just go through the rest of the actions here and then finally, in the same action, we're going to see if the player has started moving the other direction. Right, cause if that happens, we want to move to this state down here. So again, we're gonna get the velocity and then check the sign of it. If it's negative over sudden, we're gonna be in here now. the moving left state and the moving right said, They're actually pretty much identical, except for a few tweaks. For example, if we go to be moving left state, everything up here is the same with getting the position of the player exposition, and we're converting it to screen space screen Point and some here. We're comparing the player position players screen position 2.2, and and if it's smaller than that, we're going to send the player the next state and then finally, after that again, we're going to check, develops that velocity and see if it has become positive. If that's the case, we're gonna go back to moving right. So in these two states, we determines if the player is at either side of the screen. And if I think the territory is at the edge of the screening, would go to the next step, which is go from that edge to these two states. And if you pay attention, you can see that when this state is finished, it goes to the next one, and then the next one, when it's done, goes back here. So there is, say, a small loop here that I've set up to track the position and set the position of the camera to attract the position of player and said the position of the camera and what I'm essentially doing is I'm gonna find how much the character has moved one frame and I am going to translate. I'm gonna move a camera by the same amount, and until we have, we do, we test the velocity again and see if it has changed direction. So we'll keep doing that. Find the difference between the position difference between two frames and move the camera until their characters moving in the other direction so you can see we're doing the get position. Get velocity again and then checking a sign. And if the player, if the character is check moving in the other direction that we're going to send it back, Teoh very first state to decide. Well, which direction should we go into? All right, so it's the same thing down here, but we're checking for the opposite signs. Basically, when I say signs that signs for the velocity. So that's the quick overview of off what we're going to do, and that's that's go back to the scene we're working on and start creating this state 4. 27 Camera Follow Setup: Okay, so we're back in the scene we're working on. So the first thing I want to do is let's go back to the simple follow script that we had set up for the camera. And it's just really rename this clear, simple father. And I'm gonna on track this, so we're not gonna be running this state machine, okay? And now I'm gonna add a new state machine to this thing to the man camera, okay? And I'm gonna name this following, okay? I want to create a variable that hosts the player object. This is an initial state, and I'm gonna find object. We tag the play tag. I'm gonna story in the player variable. Let's just double check and see if the player object has to tag, and it doesn't say that's make sure it's got the right tack there, Trey. So when that's done other way, you can press control and click on the state to quickly create the finish transition and also, uh, control or command. If you're on the Mac and left, click on the screen on on empty space, that you can create a new state. So in the case here, we're going to try to velocity on the horizontal access. So we are going to use and get lost t to D. Since we were working to the space specified game object. Let's put the player after their and we're gonna put it being X. Right. So we need a variable friends, I must do float. I'm gonna call this player. Listen, that's and we're just gonna put it there. We're gonna do this every frame. Next, we are going to do a float sign test which decides which basically tests the sign of this float variable and see if it's positive or negative. Right now, I need to events to give to this action that's d possibly lost city and nobody to be more exact. The, um that's them there as well. So we're gonna dio if it's positive. Positive x last t. It's negative. And it's doing this every frame as well I can remember to at a transitions to the state. Okay, Now, when is when they've lost? It is positive. That means that the territory a is moving to the right of the screen. So we're gonna create the next state for that. In a comment positive lost t to that state. All right, so in this state, we know that the player is moving to the right. I want to get the position off the player and compare it to the screen space. I've We want to get the screen point of the position and compare it to 0.8. I want to leave 20% of margin there, So let's do that quickly. Here, get positioning. Today, we're gonna get the player position, and I need so I made a mistake here. Get the lastly to the We should be getting a velocity variable, not position. So let's change that. It's created me very vocal player, but not City X. Termez used that here instead. So it's not gonna be confusing. So get velocity to DS. Put in Velocity Player lost the X. And also we're gonna check Player of Lost the axe. Check the sign of this variable. Okay, moving right now, we're gonna use player position acts do every frame. Now we have the world position of the player on the X axis. That's changed that. Read that to screen point. So let's find the world to screen point, actually, and world acts would be player position, ex player, Pasta X, and we need to store Ain't a screen position. So I'm gonna day call this player Position X Also going to do every frame and I want to normal Normalize it. So just me a number between zero and one. Okay, Next I want to compare this position. Teoh, a number that I defined so flowed. Compare, and we're gonna compare position off the player to Quinn age, which is 80% of the screen space here. And if it's greater than we're gonna do something right, we're going. We're going to send us to the next sense of states where we moved the camera and make sure we do this every frame and it's call the transition event that edge and thats so add that to the state, sir. When the player is over here, we're gonna send it to the next state. Just gonna have a place over there, Okay? And finally, we want to make sure that if the character is moving in the opposite direction, we're going to send it to a different state that handles things on the other side of it screen. So I'm just gonna cook a copy the state and paste it so I can use it. I don't have to recreate some of the actions. Call this moving left. And also remember, we wouldn't want to hook up this transition. One the loss of those negative meaning characters moving this way, we're gonna go to that state. So again, these old valid actions were gonna keep. But instead of comparing it to the right side of the screen when you compare it to the left side of the screen and instead of greater than we want to say, Well, when it's smaller, when the position is smaller than point to, I'm gonna sing to control to the next eight. Okay, Okay, so that's come back to the moving right state. And now I want to get of lost t. And if it's negative, I'm gonna go to this state, and I could just quickly happy this these two actions taste them here. And I don't really care if it's positive, because I'll just stay in this state. And if it's negative, I'm going to add transition. Negative exit velocity. The Internet dish over there. Okay, I'm gonna do the same thing. Copy needs to put it down. Yeah, So if the drastic changes or in this state, we'll move it back to the moving right state. Okay, so we have those set up properly. Let's just give this a quick test before we continue. Okay, Sir, is going right. Stretching It's gonna be in moving wrote State I moving left sky. It's going to the moving left state, so that's good. And if I am yech now it goes to this state and it doesn't do anything yet, so we're kind of stuck in the state. But at least that means we are. This thing is working now with determined when we're going to start moving the camera on the characters near the edge edges off the screen. How do we actually move the camera now? I'm going to set up to states to under that and what it's going to do is basically as we kind of talked about before in the first date, I'm gonna find the difference. The distance that the character has moving one frame, and in the next state, I'm going to copy that difference to the camera. So the camera sort of mirrors the movement off the character right. So that's just do that. The first day I'm gonna find Delta or fine movement difference. I just call it found. Find Delta. Thanks. And here I want to define a new variable called player position. Acts new. And what that does is already have a player position that I got from here in approve of state. And we're gonna compare this. I'm going to use the new one and compare these two to get the distance that the Cherica has moved. Right, So let's say we're gonna get position. Can't spell spell Smith spell position. Okay, get position. And I'm gonna put the position into the player position. Axe new again in the previous state we got who put the position into player position acts here before I forget. Make sure we're getting position of the player, and we're putting that in the new variable, and I don't want to do it. Every friend I just wanted to dio do this once, and then I'm going to define we're gonna find the Delta. I'm gonna find the difference between these two numbers. So we know how much, uh, the player has moved and why I'm going to do here is I'm gonna find float operator commit. Sure, I do that I have to taking a position. And I'm just gonna dio new position miners the old position. And I'm going to store that into a number that's called into a veritable and in court thanks, which is how much the character has moved on the X axis Once that's done. Finished, it's actually moved camera, right? So we get but Delta on the X axis. So how much the characters moved. And now that's Meave Temer. Are you seeing that distance I don't want to repeat and I wanted to be world space. Now the reason why we don't want there's to be every frame is because we're gonna be looping between these two states. So essentially we will be moving the camera, his friend, But it's just not going to be in the same state. I mean, we will move the camera continuously, rather, but it's not going to be in the same state. Okay, so and I also want to use late updates, just I find it better to two moves cameras when, when we are 11 using the late update. Okay, So? So that make sure that we get the camera to follow the character with. Actually, for one thing, this is when we want to get position again. We want to get the clear position, the updated player position, and we're gonna put it, gain player position acts instead of the new one. And this is so that now we have a new baseline position. So when we go back to this state, the new position as we're subtracting it with the new position as well, that's what this. So we get the new so the original position, and then we get the next frame, we get the new position and then we get the data again. Right? So translated camera. Then get the position we're gonna put it. He played Position X, and that's basically that's if we just play that once we get to the edge of the screen, can see that camera is moving or you can't intensity character now, but the camera is moving with it. That's just duplicate floor. So we have more room here, Okay, in case of a looks good. Now we want a way to get out of this state because if you see once the character gets to the right side of the screen. We go to the follow states and they just sort of keep looping back and forth and themselves . I'm just double check it. I don't think it's following quite right. So I realized problem that we're having right now, they're just show it to you quickly here. If we play the game, let's just go into state. I'm gonna go and pause the game. So as you can see that we are at the moving the news came state and we're moving by this number, which is calculated using these two numbers here. That seems all right, but the problem is because we're doing a late update, which means there is a slight delay between update and late update were able to see the difference. We were able to see the camera moving without running into an infinite loop problem. Because that delay now, if I get rid of that and run the game, you noticed that we are going to have it is a problem. See that play America is telling us we sort of have influence infinite loop here because we're going back and forth between these two States. So what we want to do. And I realize that just now that we actually want to make sure that we spend enough time in one of these two states, we need at least one frame of it, Right? So what was happening was translating it, but we got out of the state to quickly before the camera can catch up to the character. And instead of using a late update, I'm just gonna use the regular update, which means we don't have to half that delay. We don't have to deal with it. So I'm going, Teoh show you this look action that I really like using, which is called if you go to state machine category and then go to the next frame event and all this does is basically wait one frame and then goes to this event. So this make sure that we have one friend here on one something, and that's what we need to do. Like if you start playing here, this thing now Temer is moving nicely. And we don't have that Luke problem anymore because we're making sure that you were have this new next frame event managing that stress so that's great. But as you can see, once I am at the edge of the screen, that camera starts following the camp. The character. But it doesn't stop following, which is not the desired outcome. So we need to do is basically check the velocity again. And if it's going the other direction, we want to go back to the original state where we checked velocity and see if we need to move the camera or not. So let's go to on Tunisian regime states. I'm just gonna copy these to get lost float signed test. So again, getting the player last year. Me, I don't need to do everything. And if the velocity is so, this is where we're going. Positive. If it's negative, we're gonna go to the negative velocity. Is that so bad to where we checked the velocity in the first place? Okay. And I'm just gonna track the next same event down to the party again. Safe. Let's give it a quick test and see if that's working. Okay, So go to right side of the screen. It's following the character and what leave when I go to the other direction. It stops following great Now I just need to set it up on the other side as well, which will just mainly be copy and pasting. So I'm gonna delete this for now and a copy these two states and basically set it up the same way. Except we want the opposite. So I don't need to change what's going on in the fight. Fine. Delta State. So that's fine, because just this is independent of the direction the territory's moving and, uh, see translating it. That's fine. That's fine, right? So all I need to do is basically change the float sign test action to check for the positive velocity when it changed this event to positive, lusty. And if that's the case, go back to that state. Gonna move this around a bit. So it's a slightly cleaner just cleaning this up. It okay? Still quite messy, but I think that she worked. Let's just try it. Term lead, you right to divert works fine. And now moving to left. I think I forgot to add the physics material on that rock. Could you get made? Okay, so it looks like it's working pretty well. Let's try a left again. Great. So That's how we can set up the camera, to follow the character, to sort of scroll in the right direction at the right time. It's slightly complicated, but once we've done that a few times, it's not that complicated to sort of get the hang of it. 5. 28 Parallaxing: No, we have the camera moving along with the player. That's that's looking pretty did it's ab little bit as vigil to the background while we're looking at Tamra. Okay, so that's sketchy our heart pack and find the three cloud images import all three of them escape them. So did here. Did now again, we can tweet the pictures. Two units, skeleton you've seen and they're all single sprites. So that's good track. Drag and drop didn't mean to do that. I'm just going to I checked in into the scene one by one The problem with Dragon multiple sprites into the scene as we Now that unity is going to try to create an animation out of the sprites, which is nice. But it's not what we are trying to do here, So I'm just going to sort of place them randomly, seem dio Mandy Teoh duplicate and around seeing a bit. Let's just do a few more of these. Okay, Now play. Have those clouds in the air. It's kind of a nice, nice little touch. Um, you can see they are They're being drawn before the players, so we're gonna change the or during their again Let's check the player there. Where is that zero? So I'm gonna pret these negative too. Play it. It's here now, behind the player. That's great. One thing that a lot of two D platforms do is to make objects that are further away from the camera move slower than objects that are closer to the camera. So that's that's called a parallax ing. Perfect pay relaxing schooling on what that does is it sort of gives the game a bit more death vigil, visually, some depth to the background. So right now, when we moved the character around and see that all the clouds are moving the same speed, Um and I'm gonna change that. So the first thing today and this is actually a really simple thing to do in unity, because unity is a 30 engine, so we can actually use that to our advantage. So you have to do is first go to the main camera. That's change projection from Ortho graphic to perspective, right. And then you might have to at Chesterfield V on to get the same sort of zooming distance. But what we're gonna do here is I'm going to move some of these clouds to the back. You can see them. I'm now in the three d world. If you're too d, just click on this button here. I'm gonna move thes few objects further away from timber. And as you can see, that has some doing that. They started to appear smaller on the screen when you hear them back somewhere, okay? And that's that's what you have to do now where you play because they're further away from the camera and we're in perspective, married. They are going to move slower and the ones that are closer to the camera. So that's a quick way to have parallax ing in unity. And it's kind of Ah, it's kind of a cool trick, right? And now I think I want the clouds to be a little bit figure. So I'm gonna change pixels for units 50 twice as big. And another thing that we can do here is if you notice some artifacts around the image, you can't go to filter mode and change to point. I think that the photos by linear on and that doesn't always keep for the most sort of accurate visual for these Sprite. So it can change that point point. Okay, let's take a look at that again. I should be fairly obvious that Thank you. Clouds are moving or visually. They're moving a different speed because of the position. Depositions on the Z axis kind of Indy three TV. Okay, great. So that's Parallax. 6. 29 Collect Coins: now the next thing I want to do is to add some calls in the game. The point of the game is going to be for the players to collect coins, right? So that's at that into the game. Okay, So go to your player object. And what we want to do is we're going to start a new state machine click, add component, play, my dear. No matter the first, then And this is going to be the component that handles older data that we're gonna have on the player. And primarily it's going to deal with two things. One how many coins player has collected and to let around. We're gonna talk about having health points, hp for the players so the player can take damage. So this state mission is going to handle that. So it's clicking. Now we have a new state machine, and let's deal with coins first, right? So I want to add me corn touch, and what we want to do is whenever there is, whenever there's a trigger, I object your coin trigger. Then we're gonna go two at ST, and then we're gonna add we're gonna manipulate the interject here. So it's gonna start zero. And every time we collect coins, we're gonna go to that state, you can call this idol. And then I adding this one event could collect coin, and it's gonna go to add coined. And when that's done, go back to Rideau. Okay, so that's the basic set up for the state machine. Now, let me fine an image to use for the coin. And I think there's one just here. So there are a couple different ones. Is the gold coin brown coin silver coin grab to go from dreaded tree game and then put it, I'm just gonna put this year. So I contest with thank you small. So again can a chance that Okay, so now we have this coin object in the game, Andi, because we want the player to be able to interact with it. We need to make this into a trigger object. So let's go to add component physics today, Uh, Teoh Circle Collider, since dimensions a round coin and you can see that the collider is way too big. So we're just gonna tweet the radius to build there. I think that's good enough, and we're gonna check his trigger, said the coin. Make sure that we're telling system this is a trigger object. And finally, we're gonna give it a tag. And now I already have coin as attack option. If you don't have that, then go to add tag, type it in, and then click on the object again and select that tag. Okay, so now we have that go back to the player stay machine. That data is damaging so you can select a two different can switch between the two different state missions here on what we want to do is run during the data state machine. And it's a good idea to separate state machines into sub several different ones for different aspects of the game. Right. So, um, if we decided to change how data is structured or how data works, we can still do that without having to mess with the controls, That machine, in any case, and now we have toe were in the data state machine, and in either we're gonna dio trigger foreign the coin trigger. So trigger two D event. I think this is kid, so arm trigger into two D, and if it that's felt, it by the tag coin, right? So as you can see that they fight, then click on this icon is going to show none because there is no string variables in this state machine and it's trying to find out the string variables. But if you click on that and then it's going to share or available tax in the game, So fine coin and send event go to click coin. Okay, so you have that set up. Just double check everything we've got. Those things are set up. Okay, so when a position this coin a little bit, close it down here, so it's easier to collect it. Let's just run this and see what happens. A. Pay attention to the states here and see if it goes to that corn state. There's never lets see. Take a look here clinically to d. Uh, okay, See, I should have that. So I am using and add on to playmaker. The hand does. Are you into two d? Um, physics. And what that requires is you need to have this prefab called unity make it play American unity to day in the scene. So just tracked that into your scene after you've downloaded the playmaker unity to the package. Okay, let's try that again. And I was working. Ah, again, Let's look at the player Data state machine to conceive that. Were you? Whenever the player enters this trigger, it goes to that state. Great. Now we have to do is add one to the coin count and then remove the point. Simple enough. We're gonna do it into ad one count. Add one. When this is finished, we're going to destroy the current on here is asking for a game object. So back here, we need to store the collider in a variable. So we're gonna do came object. I'm just gonna put I'm gonna start the collider that we get me into contact with into this collider Kim object that really so here I can referred to it and once destroyed that object . Gonna go back to idle. So I'm going to just make the coin count available in the inspector so it can take a look at it right now is zero and the game first starts. It's still going to be zero and marry that one because we've collected that. Quite so. That's good 7. 30 Collect Coins GUI: canal. We want a representation of how many coins you have collective. So for that, we're gonna go and create a gooey text so you can count your game object, create out there pretext, or from the drop down menu in the hierarchy panel. Gonna create Greek tax, Not agree. Taxi. As soon as you added, you can see that there's untaxed in the game view, but not in a scene view. So for those of you not familiar with Greek text, I'll just go over it quickly. You can seek re text. You can see the tax here. If you change the text here, you can see it being updated in the game. Be whether you don't see it in the scene view. So Pretext only shows up in the game. The position of Greek tax is also a bit different from the transformed positions that you use. Another game objects, so this is a screen position, so X goes from 0 to 1. You can see there, and I also why it goes from 0 to 1 zero being the bottom of the screen, one being the top of the screen position, Exposition wise theorize the left edge of the screen. And why is the right edge of the screen So when we d 0.5 point five is gonna put the tax in the center of the screen, you can change anchor in alignment. Here. Gonna put anchor at middle center. Okay. And this is going to be mine. Coin Tallinder. I'm gonna put this at the top of the screen and you can use a different font. I think that my half went here. See? No, I'm just gonna use the default like a old four than in Talic Jones. A color finding that, um for now, I'm just gonna keep it that way. So we have now a coin counter. Variable accounts. The coins that the player has collected and I was a gooey text object shows up to the player How many coins here she has collected. I'm going to change this to agree. Pretext to go a point. So now all we have to do is connecting the two right. We want to connect the coin count variable here in my state to the gooey part here. Everyone update us. Number it in the end. So there are only a few things we need to do. First, we need to remember one thing which is? The coins are in favorables, right? The corn count here is it is an end. Variable. The gooey text text variable. This requires a string variable. So what we're going to do here is we're going to convert this interoperable to a string variable so you can use it here. We want to make sure it's a text and then we also want to construct a stream. So that is, shows coin, semi colons space and then the number. And then finally will update this field. Avoid the new string that we've created my sound a bit confusing, but let's go through it and you understand what I'm talking about. So we have coin count. That's the insufferable. It's good actions that's find into to string convert into twos. Drink, action. Eso Here, we need another variable. So I'm gonna call this, make sure it's a string variable court coin count. All right, so we want to convert it's corn count, which is an invariable to corn cap string, which is the corresponding string variable. And finally you can use the format field here. Grad coin recall in space to this string. But we want to make sure that we added zero there and zero there is going to refer to the first argument in this action. So that's gonna basically grab the invariable in a string form and then add there show. That's, um Okay, so that's disabled. A destroy object just observed. Does string variable here for a second? It's plain tenants. Look at this state here. Ask you that. Giving me this correct format, that's great. So now I have to do Is passing this string variable to my guru types subject? Let's just grab the pretext component into the state machine and we're gonna set property. And here we're gonna find text, and we're gonna set it to the corn count String variable. Okay, let's give this a test. Seven words, guys, Pay attention to the point. Great. So now we are Clark tank quints. Multiple times for the same one, cause we're not destroying it. But I just wanted to check and see Make sure that this is working, So that's great. I'm also going Teoh, just make phone size a little bit bigger. 24. Yeah, and And they brought this story again. That shit. That should be it. Fork working coins