unity添加图片背景

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

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

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

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

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

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

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

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

B.      Clear Flags设置为Solid Color

C.      设置Depth的值为-1 

 

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

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/

你可能感兴趣的:(unity)