From the course: Unity 5: 2D Building an Adventure Game
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Spawn debris - Unity 2D Tutorial
From the course: Unity 5: 2D Building an Adventure Game
Spawn debris
- [Instructor] So now that we have our debris prefab it's time for us to add the debris to the explosion. Let's go ahead and select our player and scroll down to our explode script. You can double click on it in order to open it up in MonoDevelop. We're going to need a reference to the prefab itself, so at the top of our script let's add a new field. We're going to make this public and we're going to type it to our debris script, and we'll call this debris. Let's also create a public int and we'll store the total debris. Let's set this to 10. Now let's scroll all the way down to the OnExplode and above where we destroy the game object, let's spawn all the new debris. We're going to create a variable to store our reference to the current transform, we'll call this t and we'll set it to equal to the transform of the game object the script is attached to. Next we're going to create a for loop and inside this for loop we're going to use an int for i that equals zero. We're going to set i…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.