8 using System.Collections;
10 namespace Valve.VR.InteractionSystem
13 [RequireComponent( typeof( Camera ) )]
16 public float speed = 4.0f;
17 public float shiftSpeed = 16.0f;
18 public bool showInstructions =
true;
20 private Vector3 startEulerAngles;
21 private Vector3 startMousePosition;
22 private float realTime;
27 realTime = Time.realtimeSinceStartup;
35 if ( Input.GetKey( KeyCode.W ) || Input.GetKey( KeyCode.UpArrow ) )
39 if ( Input.GetKey( KeyCode.S ) || Input.GetKey( KeyCode.DownArrow ) )
45 if ( Input.GetKey( KeyCode.D ) || Input.GetKey( KeyCode.RightArrow ) )
49 if ( Input.GetKey( KeyCode.A ) || Input.GetKey( KeyCode.LeftArrow ) )
54 float currentSpeed = speed;
55 if ( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
57 currentSpeed = shiftSpeed;
60 float realTimeNow = Time.realtimeSinceStartup;
61 float deltaRealTime = realTimeNow - realTime;
62 realTime = realTimeNow;
64 Vector3 delta =
new Vector3( right, 0.0f, forward ) * currentSpeed * deltaRealTime;
66 transform.position += transform.TransformDirection( delta );
68 Vector3 mousePosition = Input.mousePosition;
70 if ( Input.GetMouseButtonDown( 1 ) )
72 startMousePosition = mousePosition;
73 startEulerAngles = transform.localEulerAngles;
76 if ( Input.GetMouseButton( 1 ) )
78 Vector3 offset = mousePosition - startMousePosition;
79 transform.localEulerAngles = startEulerAngles +
new Vector3( -offset.y * 360.0f / Screen.height, offset.x * 360.0f / Screen.width, 0.0f );
87 if ( showInstructions )
89 GUI.Label(
new Rect( 10.0f, 10.0f, 600.0f, 400.0f ),
90 "WASD/Arrow Keys to translate the camera\n" +
91 "Right mouse click to rotate the camera\n" +
92 "Left mouse click for standard interactions.\n" );