"Unity 3D" Learning Note 35: Game example--camera switch lens

Source: Internet
Author: User

Camera Switch Lens


In the game often switch the camera to observe a certain game object, can say. In 3D game development, camera switching is essential.

This time we learn to summarize how the camera switches the lens.

Code:

private Var camera0:gameobject;private var camera1:gameobject;private var camera2:gameobject;private var camera:gameob Ject;function Start () {//Get camera Object cameras = Gameobject.find ("Camera"); CAMERA0 = Gameobject.find ("Camera0"); CAMERA1 = Gameobject.find ("Camera1"); Camera2 = Gameobject.find ("Camera2");} function Ongui () {if (Guilayout.button ("Cast Side", Guilayout.height (50)) {//close Camera1 with camera2camera.active = false; Camera1.active = false; camera2.active = false;//Open camera0camera0.active = true;} if (Guilayout.button ("Cast Front", Guilayout.height (50)) {//close Camera0 with camera2camera.active = false; Camera0.active = false; camera2.active = false;//Open camera1camera1.active = true;} if (Guilayout.button ("Cast Above", Guilayout.height (50))) {//close Camera0 with camera1camera.active = false; Camera0.active = false; camera1.active = false;//Open camera2camera2.active = true;} if (Guilayout.button ("Panorama projection", Guilayout.height (50))) {//close Camera0 with camera1camera0.active = false; Camera1.active = false; camera2.active = false;//Open camera2camera.active = True;}} 

After execution:

Projecting the front:


Projecting side faces:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmzi4ote4oa==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

Projecting above:


Panorama projection:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmzi4ote4oa==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

It's worth noting that. These examples require a lot of resources, assuming that a friend wants to do this, without the relevant mapping resources can be achieved. Just update your learning notes for a complete unity primer. I will upload all the source code. Please wait patiently. Reading the previous article first will help you learn later. Thank you for watching.

"Unity 3D" Learning Note 35: Game example--camera switch lens

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.