In this video, Jesse Freeman teaches you how to destroy GameObject prefabs that move outside of the screen's visible area. This will help later on with memory management so you don't waste resources on running GameObjects the player can't see. Learning how work with GameObjects in Unity 5 is an important skill for building a 2D game.
- View Offline
- Exercise Files
- [Voiceover] So now that we have our spawner working,…let's look into how we can actually destroy objects…that go offscreen.…If you noticed before when we ran our game,…the objects will just continue.…Once they go offscreen,…they're still taking up memory…even though they're not being rendered.…So to make this more efficient,…let's go into our scripts folder.…We're going to create a new script…and we're going to call this destroy offscreen.…Then let's open this up in Mono Develop.…Let's add a few public properties to this…in order to keep track of one…when the object is off the screen…and two when it should actually be deleted.…
To get started, we'll make a public float…called offset, and we'll set this to 16.…This will represent the value of how far off of the screen…it needs to be before it gets destroyed.…Next up we'll create a private bullion for offscreen.…We'll use this as a flag to know that the object…actually is offscreen and needs to be destroyed.…Next, we're going to create a private float…for the offscreen X value.…
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.