From the course: Unity 4: 2D Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Exploding the player

Exploding the player - Unity Tutorial

From the course: Unity 4: 2D Essential Training

Start my 1-month free trial

Exploding the player

So, at this point, our Explode script isn't very dramatic. What we're going to do is add a bunch of body parts, so when the player hits a spike, he explodes into little pieces. To get started, we're going to open up the Artwork folder, go into our sprites, and we'll need to drag the body-part-sprites into the Resources folder. From there, let's open up the body parts and drag a single one into the scene. Now, let's attach our Random Sprite script, and we're going to name it body part sprites. From here, we're going to add a Circle Collider, and we're going to change its radius to 0.12. We also want to add the Player Bounce material to it. And now, let's add Rigidbody 2D for gravity. Now, if we run this, we'll see that the body part falls, and we get different types of body parts each time. From here, let's go into our scripts, and create a new C# script. We're going to call this BodyPart. And, we'll open this up in MonoDevelop. Now, let's add a few properties. So here, we're simply…

Contents