摄像机切换镜头
在游戏中常常会切换摄像机来观察某一个游戏对象,能够说。在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; }
}
执行后:
投射正面:
投射側面:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzI4OTE4OA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
投射上面:
全景投射:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzI4OTE4OA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
值得注意的是。这些样例须要非常多的资源,假设有朋友想要做出这种效果,没有相关的贴图资源是能难道达到的。只是在更新完整个unity入门的学习笔记。我将会把全部的源码上传。请大家耐心等待。先读懂之前的文章会有助于以后的学习的。谢谢观看。