"Unity3d" uses the mouse keyboard to control camera view (Instant Strategy game view): Indent, pull away, rotate

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.