本文共 886 字,大约阅读时间需要 2 分钟。
在游戏中,我们通常会遇到这样的选择界面,通常人物会显示在UI层级之前,这时候我们就需要使用一点儿小技巧。
首先,我们需要在UI中添加RawImage,大小属性自己调整,而后新建camera并照射物体,最终将camera与rawimage联系起来就行,代码如下:
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class NewBehaviourScript : MonoBehaviour { public RawImage showZombieRaw; // Use this for initialization void Start () { if (gameObject.GetComponent().targetTexture == null) { RenderTexture rt = new RenderTexture((int)showZombieRaw.GetComponent ().rect.size.x, (int)showZombieRaw.GetComponent ().rect.size.y, 16, RenderTextureFormat.Default); showZombieRaw.texture = rt; gameObject.GetComponent ().targetTexture = rt; } //} } // Update is called once per frame void Update () { }}
最终实现效果如下:
转载地址:http://nawli.baihongyu.com/