Join Jesse Freeman for an in-depth discussion in this video Random sprite, part of Unity 5: 2D Building an Adventure Game.
- [Instructor] Let's take a look…at how we can add a little bit more variety to our Crystal.…We're going to create a script…that will change out the Crystal sprite.…In order to do this, we'll randomly set…one of the other Crystal sprites…when the Crystal is instantiated in our scene.…Let's go ahead and create a new script…inside of our Jetroid Scripts folder…and we're going to call this RandomSprite.…Once you've created the script, open it up in MonoDevelop.…Now we need an array to store the sprites…we're going to use in the script.…
Let's go ahead and create a new public field.…We're going to type this to Sprite and turn it into an array.…And here, we'll give it the name sprites.…Inside of Start, we're going to get a reference…to the SpriteRenderer,…and we're going to set the sprite field's value…to equal our sprites array.…And in order to pick a random number,…we're going to use the Random class's Range method.…
We'll start at zero and we'll use the sprites.Length…as the maximum number in the range.…Let's go ahead and save this and go back into Unity.…
- Optimizing sprites and draw cells
- Cutting up sprite sheets
- Building animations
- Changing animations
- Creating a player
- Moving the player
- Building a level with a simple map
- Creating interactive objects
- Creating alien enemies
- Switching between scenes
Skill Level Intermediate
Careers in the Game Industrywith Christian Bradley1h 19m Beginner
Build a Real-Time Strategy Game with Unity 5with Dan Violet Sagmiller3h 46m Intermediate
1. Working with Sprites
2. Working with Animations
3. Creating a Player
4. Moving the Player
5. Building a Level
6. Interactive Objects
7. Alien and AI
8. Managing Scenes
Next steps1m 9s
- 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.