Time for action - add the sample code to your Script

Add the new code to your existing game code. You'll need to shuffle a few lines around. Here it is with the new stuff highlighted:

var smooth = 2.0; var tiltAngle = 30.0; function Update () { var halfW:float = Screen.width/2; transform.position.x = (Input.mousePosition.x - halfW)/halfW; var halfH:float = Screen.height/3; transform.position.z = (Input.mousePosition.y - halfH)/halfH; // Smoothly tilts a transform towards a target rotation. var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle; var tiltAroundX = Input.GetAxis("Vertical") * tiltAngle; var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); // Dampen towards the target rotation transform.rotation = Quaternion.Slerp(transform.rotation, ...

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.