Join Jesse Freeman for an in-depth discussion in this video Destroying obstacles offscreen, part of Unity 5: 2D Essential Training (2015).
- [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 gonna create a new script…and we're gonna call this DestroyOffscreen.…Then let's open this up in MonoDevelop.…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 boolean 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 gonna create a private float…for the offscreenX value.…
Super Zombie Runner riffs off the popular endless runner genre: a one-button casual game that's not only fun to play but exciting to build. The focus of the work is a reusable code base that you can extend and make your own, while learning the basics of object pooling, supporting multiple screen resolutions, tracking scoring, and multi-platform publishing. Along the way, Jesse covers key Unity features, such as working with sprites, creating animations, and leveraging the UI components.
- Working with sprites and animation
- Creating the player
- Spawning GameObjects
- Adding obstacles and collisions
- Building the game objects and logic
- Managing game state
- Creating pixel-perfect cameras
- Designing for multiple screen resolutions
- Adding scores
- Optimizing performance
- Publishing to desktop, web, and mobile platforms
Skill Level 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. Adding UI
8. Creating More Obstacles
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
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.