Somebody get me a bucket

A common programmer mantra is "duplication is evil." The idea is that any time you type the same thing twice, you could be wasting time and effort. Remember that the less typing we do, the less likely we are to drop dead from the programmer illness I totally fabricated.

Notice that we have some duplication in this line:

transform.position.x = Input.mousePosition.x Screen.width/2)/ (Screen.width/2);

We've typed Screen.width/2 twice. That won't do! For starters, typing makes my hands tired. What's more, we're forcing the computer to do that complicated math calculation twice. Why not do the calculation once and ask the computer to remember the result? Then, any time we want to talk about the screen's midpoint, we can ask the ...

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.