In this video, Jesse Freeman teaches you how to dynamically resize the 2D box collider on your recycled GameObjects so they correctly collide with the player. You'll do this by getting the size of the sprite and adjusting the 2D box collider dimensions accordingly. Learning how to create a reusable object pool system in Unity 5 is an import skills for building a 2D game.
- View Offline
- Exercise Files
- [Voiceover] Now, in the last video,…we added random sprites to each of our object.…And we notice, that the collider for each of these objects…isn't correctly resizing itself.…We're also able to see…that every time we create a new object,…we are able to find other scripts…that contain the IRecycle interface.…So let's go back in and clean all this stuff up.…The first thing we're gonna wanna do,…is go back into our recycle script.…Once it opens up, let's delete this debug statement,…since we no longer need it,…as we can see that it's working.…
Next, let's go into our obstacle class,…and add in the logic we need…in order to resize the collider.…The easiest way for us to do this,…is to get a reference of the collider,…and then change it's size to the size of the sprite.…Here, I'll create a variable for the collider,…and we'll use GetComponent to find a reference…of the box collider 2D.…Next, we can tell the collider size,…that it should equal the renderer's bounds size property.…
This will give us the correct size…based on the current sprite in the renderer.…
Start watching to learn how to convert artwork into sprites, create repeating background textures with Unity's TexturePacker, and build reusable game objects such as players, obstacles, and enemies. Jesse also covers the basics of object pooling, working with custom UI components, and multiplatform publishing.
- Importing artwork
- Editing sprites
- Creating repeating background textures
- Building reusable obstacles
- Recycling game objects
- Building an object pool
- Creating the player
- Starting and ending the game
- Displaying and saving the score
- Adding menus and text
- Publishing a Unity game in different formats
Skill Level Beginner
Advanced Unity 3D Game Programmingwith Michael House3h 45m Advanced
Unity 5 2D: Optimizing Graphicswith Jesse Freeman28m 2s Intermediate
1. Working with Sprites
2. Creating Repeating Textures
3. Creating Obstacles
4. Object Pooling
5. Creating the Player
6. Setting Up the Game
7. Polishing the Game
8. Creating More Obstacles
Publish to different formats5m 42s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.