解決步驟:
1.添加一個攝像機,命名為BackgroundCamera,然后在Layer添加一個background層。並且將plane拖放到改相機節點下。 然后將BackgroundCamera和Plane都置於background層,修改ClearFlags未Depthonly深度渲染,並且設置 CullingMask為只看到background層,還有設置Depth為-1,說明背景層是最深,其他model所在的相機的Depth是 0,NGUI的是1,這里層次關系就是NGUI在最前面,model層其次,然后是背景層,這樣確保3D模型在背景的前面!
2.同樣的操作,將MainCamera設置一下,注意的就是,將MainCamera的CullingMask不能包含background層,也就是讓它看不到背景層,不然還是會出現背景遮擋住模型的情況。
3.在plane上添加一個腳本,用於動態在plane上加載貼圖
01.
using UnityEngine;
02.
using System.Collections;
03.
using System.Collections.Generic;
04.
05.
public
class
AddBackground : MonoBehaviour
06.
{
07.
public
Texture2D mtexture;
08.
09.
void
Awake()
10.
{
11.
// Texture2D mtxture = new Texture2D(Screen.width, Screen.height);
12.
// renderer.material.mainTexture = mtxture;
13.
// mtxture.Apply();
14.
15.
gameObject.AddComponent<guitexture>();
16.
}
17.
18.
// Use this for initialization
19.
void
Start()
20.
{
21.
guiTexture.texture = mtexture;
22.
transform.localScale =
new
Vector3(
0
,
0
,
0
);
23.
transform.localPosition =
new
Vector3(
0
,
0
,
25
);
24.
guiTexture.pixelInset =
new
Rect(
65
,
0
, Screen.width, Screen.height);
25.
}
26.
}</guitexture>
上面Start方法中設置position的z軸屬性是原來嘗試的,想通過z軸來進行深度的修改后來發現行不通,還是層的關系影響渲染的深度。
4.效果圖
