Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Renderer))]
public class RenderGUIToTexture : MonoBehaviour
{
public RenderTexture texture;
public Texture2D background;
void Start ()
{
if (texture == null || background == null)
{
Debug.LogError ("Both texture and background properties need to be set. Please correct and restart.");
enabled = false;
return;
}
renderer.material.mainTexture = texture;
}
void OnGUI ()
{
if (Event.current.type == EventType.Repaint)
{
RenderTexture active = RenderTexture.active;
RenderTexture.active = texture;
//GUI.matrix = thisIsFiddly;
GUI.DrawTexture (new Rect (0.0f, 0.0f, texture.width, texture.height), background);
GUI.skin.GetStyle ("Box").Draw (new Rect (20.0f, 20.0f, 100.0f, 30.0f), "Hello, world!", false, false, false, false);
RenderTexture.active = active;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment