摄像机切换镜头
在游戏中经常会切换摄像机来观察某一个游戏对象,可以说,在3D游戏开发中,摄像头的切换是不可或缺的。这次我们学习总结下摄像机怎么切换镜头。
代码:
private var Camera0: GameObject; private var Camera1: GameObject; private var Camera2: GameObject; private var Camera: GameObject; function Start() { //获取摄像机对象 Camera = GameObject.Find("Camera"); Camera0 = GameObject.Find("Camera0"); Camera1 = GameObject.Find("Camera1"); Camera2 = GameObject.Find("Camera2"); } function OnGUI () { if(GUILayout.Button("投射侧面",GUILayout.Height(50))) { //关闭Camera1与Camera2 Camera.active = false; Camera1.active = false; Camera2.active = false; //打开Camera0 Camera0.active = true; } if(GUILayout.Button("投射正面",GUILayout.Height(50))) { //关闭Camera0与Camera2 Camera.active = false; Camera0.active = false; Camera2.active = false; //打开Camera1 Camera1.active = true; } if(GUILayout.Button("投射上面",GUILayout.Height(50))) { //关闭Camera0与Camera1 Camera.active = false; Camera0.active = false; Camera1.active = false; //打开Camera2 Camera2.active = true; } if(GUILayout.Button("全景投射",GUILayout.Height(50))) { //关闭Camera0与Camera1 Camera0.active = false; Camera1.active = false; Camera2.active = false; //打开Camera2 Camera.active = true; } }
投射正面:
投射侧面:
投射上面:
全景投射:
值得注意的是,这些例子需要很多的资源,如果有朋友想要做出这样的效果,没有相关的贴图资源是能难道达到的。不过在更新完整个unity入门的学习笔记,我将会把所有的源代码上传,请大家耐心等待。先读懂之前的文章会有助于以后的学习的。谢谢观看。
【Unity 3D】学习笔记三十五:游戏实例——摄像机切换镜头,布布扣,bubuko.com
【Unity 3D】学习笔记三十五:游戏实例——摄像机切换镜头
原文地址:http://blog.csdn.net/u013289188/article/details/37650779