Terminal velocity is a myth bombs fall faster

Ignoring the laws of physics for a second, let's look at the 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 FallingObjectScript. Change this line:

transform.position.y -= 1;

to:

transform.position.y -= speed;

Then for each object, input a different number for the speed value in the Inspector panel. 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 saving you time and effort, it's causing you grief. As a game developer, you need to decide what sort of structure best suits ...

Get Unity 3D Game Development by Example 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.