O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required