silikonkitchen.blogg.se

Particle playground 2 unity tutorial
Particle playground 2 unity tutorial





particle playground 2 unity tutorial

Then we check if the player is moving left or right and flip the X scale depending on that. It gets the horizontal axis (-1 to 1) which maps to the left/right arrows and A/D keys. To begin with our functionality, let’s add a “Move” function. Public ParticleSystem jetpackParticle // ParticleSystem of jetpack Public Animator anim // Animator component Public Rigidbody2D rig // Rigidbody2D component Private float stunStartTime // time that the player was stunned Public float stunDuration // duration of a stun Public bool grounded // is the player currently standing on the ground? Public float flyingSpeed // force applied upwards when flying Public float moveSpeed // force applied horizontally when moving

particle playground 2 unity tutorial

Public PlayerState curState // current player state First, we have our state, some values for speeds and durations and finally a list of components that we can access. Now back in our class, let’s add the variables we’re going to be using. If you look back at the player animation controller, you will see that the “State” float value correlates to the id of each enum value. This enum will contain the player’s current state. Opening it up, we can start by adding a new enumerator called “PlayerState” at the top of our class. To begin, let’s create a new C# script called “PlayerController” and attach it to the player object we just made. Position it in a way so it comes out from the player’s jetpack. To add some interesting visual elements, we’ve got a jetpack particle that will blast particles when the player flies.ĭrag in the “FlyParticle” prefab into the scene as a child of the player. This is a number we’ll talk about more when we script the player.

particle playground 2 unity tutorial particle playground 2 unity tutorial

Our various animations play determined based on the “State”. If you double click on the player controller, you will see in the Animator window what it’s made up of. So to add it, just add an Animator component and set the controller to be the “Player” controller. They’ve all been connected and setup inside of the “Player” animation controller. This will prevent the player from falling over.įor the player, if you downloaded the project files you will have some animations. Set the “Linear Drag” to 1 and enable “Freeze Rotation”. We also need to add a Rigidbody2D component. Capsule collider allows us to glide much smoother. We’re not using a box collider because they can get stuck if moving along a surface with multiple other colliders. Then set the tag, layer, and sorting layer to “Player”. Before jumping into scripting it, we need to set up a few things first.ĭrag the “Player_Default” sprite into the scene (part of the Player sprite sheet). For me I used a blue/green color (hexadecimal: 4BC1AC). Click on the camera and change the “Clear Flags” property to Solid Color. So what we’re going to do is change the color to something a bit more ‘alien’. Now at the moment, our background is just the default blue. In our case we’re having 4 possible answers, but you can have as many as you want. This basically means that it’s on the same layer as the ship but it will render in-front. Then, set the sorting layer to “Ship” and add a BoxCollider2D component, resizing it so it fits the ship.įor our tubes, we’re going to drag in the “Tube” sprite, add a BoxCollider2D, set the tag to “Entrance” and sorting layer to “Ship” with an order in layer to 1. You may see that it’s a bit too small, so just increase the scale to 1.15. Next, drag in the “Ship” sprite to the top of the frame. Now duplicate that tile and lay them out horizontally along the bottom border of the camera frame. If you don’t have a “Floor” tag, just add one. To make the floor usable, we need to add a BoxCollider2D component to the tile and set its tag to “Floor”. Then, drag in the “GroundTile” sprite as a child of the object. This is going to be where we store all of our ground tiles. Now create an empty GameObject (right-click Hierarchy > Create Empty), and call it “Ground”. Note: Make sure that the sorting layers are in that specific order, as this determines what sprites render in front of others. Sorting Layers: Background, Jetpack, Player, Obstacle, Ship, UI If you’ve downloaded the project files and are using that, then you can skip this step. Go to the Game window and set the aspect ratio to 16:9.įor this project, we’re going to need to add in some tags, sorting layers, and one layer. Since we’re working in 2D and the fact that we’re utilizing the whole height and width of the screen, it’s important that it’s consistent across most platforms. This is due to the scale we’re working with. Then we need to make sure that our “Main Camera” has an orthographic size of 5. First of all, create a new 2D Unity project.







Particle playground 2 unity tutorial