Unity2D 背景图铺满与Camera.Size的计算公式

本文介绍在Unity中制作2D游戏时如何调整Camera的Size以使背景图正确铺满显示。通过计算公式ScreenHeight/2/PixelToUnits得出Camera的Size值,并给出具体例子。

在unity制作2D游戏的教程,背景图sprite铺满显示时Camaer的Size调到多少合适,作个笔记。

资源参数

background.png 2048x640,Sprite的像素单位:100

imageimage

调节camera.size

当camera的size=5,背景的显示效果

imageimage

Camera的Size=3.2的背景的显示效果

image

 

计算公式 

计算公式为:Screen Height/2/Pixel To Units=Main Camera.Size

对于2048x640的背景图,像素为100单位的比例,Camera的Size=640/2/100=3.2

For example, consider a Sprite imported from a 500 pixels wide image. The following table shows the different widths your GameObject would have when rendering that Sprite at different scales along the x-axis, using different values for Pixels to Units:

size comparisons with varying scales and pixels to units

background.png is 640 pixels tall, and the background Sprite has a Pixel to Unit ratio of 100, so the backgroundobject in the Hierarchy will be 6.4 units tall. However, the orthographic camera’s Size property measures half the height of the screen, so it should be half the height of the background, in units, or 3.2.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值