using UnityEngine;
using UnityEngine.UI;

public class Test:MonoBehaviour{
	
	public RawImage rawImage;
	public Camera cam;

	private RenderTexture m_renderTexture;
	
	private void Start(){
		m_renderTexture=new RenderTexture(512,512,16,RenderTextureFormat.ARGB32);

		rawImage.texture=m_renderTexture;
		cam.targetTexture=m_renderTexture;
		//必须为 CameraClearFlags.SolidColor或CameraClearFlags.Depth,CameraClearFlags.Nothing 时会不显示
		cam.clearFlags=CameraClearFlags.SolidColor;
		
		//CameraClearFlags.SolidColor时会有背景色,需要设置背景色透明
		Color color=cam.backgroundColor;
		color.a=0f;
		cam.backgroundColor=color;
	}
}
  • 注意:Camera.clearFlags 必须为 CameraClearFlags.SolidColor或CameraClearFlags.Depth,CameraClearFlags.Nothing 时会不显示
    CameraClearFlags.SolidColor:会有背景色,需要设置Camera背景色为透明
    CameraClearFlags.Depth:不会清除上一次渲染的内容,会出现重叠花屏

原文地址:https://www.cnblogs.com/kingBook/p/14160483.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐