
3.3 摄像机游戏对象
摄像机(Camera)是观察场景的窗口,每个场景至少需要一个摄像机才能显示其中的内容。
一个场景中可以存在多个摄像机。例如,在3D游戏中,要动态显示小地图,其中的一个方法就是添加一个从顶部垂直往下观看的摄像机,这样就能显示当前玩家所在的位置以及玩家周围的环境和情况。
摄像机最常用的属性有“Culling Mask”“Projection”“Depth”,如图3-11所示。

图3-11
● Projection
Projection(投影)模式有两种:Perspective(透视)和Orthographic(正交)。在Perspective(透视)模式下,物体近大远小,主要用在3D游戏下。在Orthographic(正交)模式下,物体不会因为远近而有大小的变化,主要用在2D游戏中。
例如:在场景中,前后错落地设置了几个方块,如图3-12所示。当投影为透视模式时,方块近大远小,显示的结果如图3-13所示。当投影为透视模式时,方块不会因为距离远近而有大小变化,显示的结果如图3-14所示。

图3-12

图3-13

图3-14
● Culling Mask
Culling Mask(剔除遮罩)设置摄像机能够看到的对象。每个游戏对象都有一个Layer(图层)属性,根据游戏对象的图层和摄像机的剔除遮罩设置,可以决定该物体是否在摄像机中显示。游戏对象默认的图层是Default。
例如:将摄像机的Culling Mask(剔除遮罩)设置为只显示图层为Default的游戏对象,如图3-15所示。

图3-15
在摄像机前面添加一个球体,如图3-16所示。将球体的图层设置为Default之后,在运行状态就看不到球体了,如图3-17所示,需要注意的是,这样设置只是摄像机看不到了,但是这个球体真实存在并且会起作用。

图3-16

图3-17
● Depth
当一个场景中出现多个摄像机的时候,Depth(深度)属性决定显示的前后。