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 is the code with the new stuff highlighted:
var smooth : float = 2.0; var tiltAngle : float = 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 : float = Input.GetAxis("Horizontal") * tiltAngle; var tiltAroundX : float = Input.GetAxis("Vertical") * tiltAngle; var target : Quaternion = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ); // Dampen towards the target rotation transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth); }
Tip
Nobody's perfect
In my version of the Script Reference,...