- Unity3D平台AR与VR开发快速上手
- 吴雁涛
- 428字
- 2025-02-26 12:47:21
3.2 摄像机
摄像机是观察场景的窗口,每个场景至少需要一个摄像机才能显示其中内容。一个场景中可以存在多个摄像机。例如,3D游戏中,动态显示小地图,其中的一个方法就是添加一个从顶部垂直往下观看的摄像机,这样就能显示当前玩家的位置以及周围的环境和情况。
摄像机最常用的属性有“Culling Mask”“Projection”“Depth”,如图3-6所示。

图3-6
1. Projection
Projection(投影)模式有两种:Perspective(透视)和Orthographic(正交)。Perspective(透视)模式下,物体近大远小,主要用在3D游戏下,如图3-7所示。

图3-7
Orthographic(正交)模式下,物体不会因为远近而有大小的变化,主要用在2D游戏中,如图3-8所示。

图3-8
2. Culling Mask
设置摄像机能够看到的对象。每个对象都有一个Layer属性,根据对象的Layer属性和摄像机的Culling Mask设置,可以决定该物体是否在摄像机中显示。
例如:添加一个方块,Layer是water,如图3-9所示。

图3-9
再添加一个球体,Layer是default,如图3-10所示。

图3-10
在MainCamera的“Culling Mask”设置中,去掉water,如图3-11所示。

图3-11
这时候运行,无法看到方块,如图3-12所示。

图3-12
3. Depth
当一个场景中出现多个摄像机的时候,该属性决定显示的前后。