Skip to Main Content
Mobile Game Development with Unity
book

Mobile Game Development with Unity

by Jonathon Manning, Paris Buttfield-Addison
August 2017
Beginner content levelBeginner
464 pages
9h 18m
English
O'Reilly Media, Inc.
Content preview from Mobile Game Development with Unity

Chapter 11. Adding Weapons and Targeting

Now that you’ve got a spaceship flying around, it’s time to add more gameplay to the whole thing. First, you’ll be adding weapons to your spaceship; once that’s done, you’ll need a target to shoot at.

Weapons

Every time the ship fires its weapons, it shoots a laser bolt that flies forward until it either hits something or runs out of time. If it hits something, and that other object is able to take damage, then the shot needs to convey information to that object.

We can do this by creating an object that has a collider, and travels forward at a certain rate (much like the spaceship). There are a number of different possibilities for how the shot could appear—you could create a 3D model of a missile, create a particle effect, or create a sprite. The specifics are up to you, and don’t affect how the shot actually behaves in the game.

In this chapter, we’ll use a trail renderer to display the shot. A trail renderer creates a trail behind it as it moves, which eventually disappears. This makes it especially good for representing moving objects, such as swinging sorts and flying projectiles.

The trail renderer for the shot will be a simple one: it will leave behind a thin red line, which gets thinner and thinner over time. Because the shots will always be moving forward, this will create a good-looking “blaster bolt”‐like effect.

The nongraphical component of the shot will be implemented with a kinematic rigidbody. Ordinarily, rigidbodies respond ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mobile Game Development with Unity 3D 2019

Mobile Game Development with Unity 3D 2019

Raja Biswas

Publisher Resources

ISBN: 9781491944738Purchase bookErrata Page