From the course: Unity 5: 2D Level Design

Unlock the full course today

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

Alien projectile simple

Alien projectile simple - Unity Tutorial

From the course: Unity 5: 2D Level Design

Start my 1-month free trial

Alien projectile simple

- [Instructor] Now that we have a new alien, let's create the projectile our alien will fire. Inside of our JetroidLevelDesign Artwork folder and inside of alien-c folder is an alien-spit sprite. Let's go ahead and drag this into our scene. First, we're going to add a Rigidbody 2D to it so that we have gravity. Next, we're going to add a Circle Collider. Now, let's go ahead and rename this to AlienSpit. Now, we're going to want to create a script for our projectile that automatically destroys it whenever it detects a collision. So let's go into our Scripts folder, create a new C# script and call this Projectile. Then let's open this up in MonoDevelop. This script is going to be really basic. In fact, we can delete the Start and Update methods. First, we're going to create a void OnDestroy method and inside of this we'll simply call Destroy and pass in a reference to the gameObject. Next, we'll need another method called void OnCollisionEnter2D. This will accept a Collinsion2D and…

Contents