This Teachers Day Amazed your teacher with online cake.

Teachers Day will be held on the 5th of September, Where we present our gratitude towards our teacher in order to respect them And while honoring them we tend to give some gifts in terms of heartfelt…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




From Prototype to Work of Art

You have a prototype working with simple objects and it feels just as you envisioned. Now it is time to add some art and get the look you want. I will show you how to take a 3D object and turn it into a 2D work of art.

Let’s take the Player game object in our game and change it from something ordinary.

To a great piece of 2D art.

The first step is to import your art assets into your project. Simply drag and drop your sprites into your Assets folder in the Unity editor.

Verify they got imported in as a sprite by selecting one of them and checking the Texture Type is set to Sprite(2D and UI).

If this is not the case and your sprites got imported as Default texture type we can fix this. Simply click the drop-down arrow and select Sprite from the list. Be sure to click apply to apply the changes.

Now we look at the components attached to the player. The one thing that makes the player the player is simply the Player script we have attached to it.

We can convert a 3D object into a 2D object in many ways. I will show you how to rebuild the player. Find the player image we want to use in your sprites and drag it into the hierarchy.

Set the scale to what fits your game. Rename the object to Player, give it the player tag, and lastly add the Player script to the object. Now we need to get the values from the other player script and add them to this script. Just right-click on the original Player script and select copy component

Then head over to the new Player object, right-click the Player script, and select paste component values.

Now we can delete the original player object from the hierarchy. Time to test everything out to make sure it works. You will notice one thing right that still needs to be addressed.

We do not collide with enemies anymore. There are a few reasons for this. Our player object does not have a collider and the player is 2D while the enemies are 3D. First, let’s add a collider to the player. It needs to be a Box Collider 2D since our player is 2D. Then set the Is Trigger to true.

The collider we added to too large for the sprite image.

To resize it you can change the values in the inspector.

Or click the Edit Collider button and move them by hand. Once you are done adjusting it click the Edit Collider button again.

Now the player is set up, we need to do the same for the Enemy object. However, we need to remember to add the rigidbody to the enemy. In addition, this component needs to be 2D. Finally, set the gravity scale to 0 as we do not want gravity to affect this object.

Next is the Laser game object. This process is the same as the Enemy.

Run the game to test our changes.

Our collisions are still not working. The reason for this is now our code. We have Uinity looking for 3D collisions.3

We need to change this code to fit our new 2D objects by adding 2D to the end of the method name and the collider parameter.

Test the game now to see if it works.

Now the functionality is back and works as it did before. One last thing to make it look even better is to add a background to let the player know we are in space. Drag your background into the scene and resize it to cover the screen space.

Now we have another issue. The background is rendered on top of the player.

To fix this we need to add Sorting Layers. This is found in the Sprite Renderer of the Game Objects.

Add the Background and Foreground sorting layers. The order it is done matters. From top to bottom is the order they are drawn. So we want the background rendered first so it will be the first item in the list followed by Foreground.

Then we set our Player, Enemy, and Laser to the Foreground Sorting Layer. The background will be on the Background Sorting Layer.

Now we can test and see how it all looks together.

Now it looks like a real game. Now it’s your turn to get out there and build!!!!

Add a comment

Related posts:

Recommendations For A Git Beginner

I started using Git several years ago. The sophisticated way in which Git swaps files back and forth “under the hood” (inside the mysterious .git folder) when changing branches still amazes me to…

Making Good Metrics

We all know we need metrics, but to be useful, the metrics need to be comprehensive, consistent, and reliable. Above all, they need to tell us something we need to know in order to make a decision…