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