Write a demo today to use the mouse keyboard to control the three-dimensional perspective, so wrote a script for control.
The script can be used for immediate strategic game viewing angles, providing indentation, stretching, and rotation. While holding down the right mouse button, moving the mouse can realize the effect of first person view.
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classCameracontroller:monobehaviour {5 6 7 Public floatnear =20.0f;8 Public floatFar =100.0f;9 Ten Public floatSensitivityx =10f; One Public floatSensitivityy =10f; A Public floatSensitivetyz =2f; - Public floatSensitivetymove =2f; - Public floatSensitivetymousewheel =2f; the - - voidUpdate () { - //wheel for Lens indentation and zooms + if(Input.getaxis ("Mouse Scrollwheel") !=0) - { + This. Camera.fieldofview = This. Camera.fieldofview-input.getaxis ("Mouse Scrollwheel")*Sensitivetymousewheel; A This. Camera.fieldofview = Mathf.clamp ( This. Camera.fieldofview, near, far); at } - //right mouse button for viewing angle rotation, similar to first person view - if(Input.getmousebutton (1)) - { - floatRotationX = Input.getaxis ("Mouse X") *Sensitivityx; - floatRotationY = Input.getaxis ("Mouse Y") *Sensitivityy; inTransform. Rotate (-rotationy, RotationX,0); - } to + //keyboard buttons ← and → achieve horizontal rotation of perspective - if(Input.getaxis ("Horizontal")!=0) the { * floatRotationz=input.getaxis ("Horizontal") *Sensitivetyz; $Transform. Rotate (0,0, RotationZ); Panax Notoginseng } - } the}
Drag the script directly onto the camera to use the ~
"Unity3d" uses the mouse keyboard to control camera view (Instant Strategy game view): Indent, pull away, rotate