unity添加图片背景

1.       创建一个新的摄像机,命名为Background Camera

2.       新建GUI Texture,命名为Background Image

3.       Background ImageInspector面板中点击Layer下拉窗口,选择“Add Layer

4.       在打开的面板中的 User Layer 8(如果你之前没有创建的话默认可以使用的第一个就是它!),添加一个新的层名称为“Background Image

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行

5.       Hierachy面板中选择Background Image,并将你准备的背景图片添加给它,在Pixel Inset面板中设定XYWidthHeight值,使其可以适当的填充界面。

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行

6.       现在将该GameObjectLayer值设置为之前你添加的Background Image

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行

7.       现在在Hierarchy面板中选择Background Camera,并在Inspector面板中做如下的调整:

A.      取消选择除GUILayer以外的 Flare LayerAudio Listener

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行

B.      Clear Flags设置为Solid Color

C.      设置Depth的值为-1 

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行
 

D.      设置Culling Mask,第一步选Nothing然后选择Background Image,最终设置好的情况如下:

Unity3d 使用图片作为3D背景 - Neo - 生命,本是修行

8.       现在选择另外一个Camera(默认是Main Camera),在Inspector面板中进行如下设置:

A.      Clear Flags设置为“Depth Only

B.      设置Culling Mask,取消选择“Background Image”,这将会导致Culling Mask的选项显示为Mixed…

这将形成GUI TextureBackground Camera来进行渲染,其他都由Main Camera进行渲染,且对于其他Camera(例如:其他Camera角度)你想要使用的,只要重复以上两上步骤就可以了!


More:

thanks for this Duck, I was looking for the same thing. Query though, is there anyway to stop the clipping for a full background image when aspect ratio is changed?

(Mar 23'10 at 8:31 PM)RobF

It's much better if you set all the pixel inset values to 0, and set the scale to (1, 1, 1) instead. Otherwise, the background image doesn't adapt to different screen sizes. The only possible drawback is that the background image will get stretched or squished with different aspect ratios than the one you used to create the game. If this is not desirable, you can use a script like this one: http://www.unifycommunity.com/wiki/index.php?title=GuiRatioFixer

(Apr 22'10 at 7:16 AM)Eric5h5

In 3.2, when I do all the above, the 'background' image is drawn really as a 'foreground' image in the Editor, all my other geometry behind the texture. I changed 'depth', no help. Anyone?

(Mar 01 at 5:21 AM)DaveA

This solution works excellently. My only problem is when I go to actually make the background scroll, it stutters every now and then as it moves.

I am adding an offset*Time.deltaTime every update to the pixelInset.x. Is there a better way to make the background scroll? Code is below.

function Update () { var xVel : float = -xVelocity*Time.deltaTime; background1.pixelInset.x += xVel; background2.pixelInset.x += xVel; }

文章出处:http://specialwolf.blog.163.com/blog/static/124466832201342544511549/

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值