22 lines
794 B
C#
22 lines
794 B
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class DrawRender : MonoBehaviour
|
||
{
|
||
public SpriteRenderer render;
|
||
public RenderTexture renderTexture;
|
||
|
||
public void Start()
|
||
{
|
||
// 创建一个临时的Texture2D,用于存储RenderTexture的像素数据
|
||
Texture2D texture2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
|
||
// 将RenderTexture的内容拷贝到Texture2D中
|
||
texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
|
||
texture2D.Apply();
|
||
// 创建Sprite
|
||
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f);
|
||
render.sprite = sprite;
|
||
}
|
||
}
|