Created
April 27, 2011 11:44
-
-
Save AngryAnt/944114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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