Unity 4.x Game Development by Example Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Screen coordinates versus World coordinates

Click on the Input.mousePosition entry and check out the resulting page. The Script Reference tells us that we have a new origin to deal with. Unity treats our screen like a flat, 2D plane, with (0, 0)—the origin—in the bottom-left corner of the screen like a bar graph from fourth grade.

Screen coordinates versus World coordinates

We have a code example here, but it looks a little hairy. What's a Physics.Raycast? I have no idea. And how do we get the x, y, and z values for Input.mousePosition?

The answer is a tiny bit sneaky. Look at the top of the screen where it tells us that Input.mousePosition is a Vector3. What's a Vector3? I dunno. Click on it. Ah, the resulting page tells us that a Vector3 has x, y, and z properties along with a slew of other useful stuff. That shall do nicely.

Screen coordinates versus World coordinates