Hang this script on a camera
usingUnityengine;usingSystem.Collections; [Requirecomponent (typeof(Camera))] Public classUimodelcamera:monobehaviour {//Render Texture Property Public intWidth= the; Public intHeight = the; Public intDepth = -; //The model to watch PublicGameobject Model; //offset from where the model is located PublicVector3 Offset; //view offset from the location of the model PublicVector3 Lookatoffset; //which uitexture to use the render Texture that the camera renders Publicuitexture Texture; Privaterendertexture mrendertexture; PrivateCamera Mcamera; voidAwake () {Mcamera= gameobject.getcomponent<camera>(); Mrendertexture=Newrendertexture (Width, Height, Depth); Mcamera.targettexture=mrendertexture; } //Use this for initialization voidStart () {Setmodel (Model); SetTexture (Texture); } voidOnDestroy () {Destroy (mrendertexture); } //set up all the watched models Public voidSetmodel (Gameobject obj) {Model=obj; if(NULL!=Model) {gameObject.transform.position= Model.transform.position +Offset; GameObject.transform.forward= Model.transform.position + Lookatoffset-gameObject.transform.position; Mcamera.cullingmask=1<<Model.layer; } } // Public voidsettexture (uitexture texture) {Texture=texture; if(NULL!=Texture) {Texture.maintexture=getrendertexture (); } } Publicrendertexture getrendertexture () {returnmrendertexture; }#ifUnity_editorvoidUpdate () {Setmodel (Model); SetTexture (Texture); }#endif}
Render the object onto a piece of uitexture