Terminal velocity is a myth – bombs fall faster

Ignoring the laws of physics for a second, let's look at how to make the two objects fall at different speeds using the same script. One solution is to declare a variable called speed at the top of the FallingObject script.

var speed:int;

Change the following line:

transform.position.y -= 50 * Time.deltaTime;

to:

transform.position.y -= speed * Time.deltaTime;

Then for each object—the bomb and stein Prefabs—input a different number for the speed value in the Inspector panel. Try 30 for the stein and 50 for the bomb. Two objects, one script, and two different speeds. Awesome? Confirmed: awesome.

Tip

Know when to double down

At some point, objects become different enough that sharing a script is no longer ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.