Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created April 27, 2011 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/944114 to your computer and use it in GitHub Desktop.
Save AngryAnt/944114 to your computer and use it in GitHub Desktop.
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