I need to render a cube created in a script to a texture. How do I do this? I want it to look something like this ![]()
![]()
I need to render a cube created in a script to a texture. How do I do this? I want it to look something like this ![]()
![]()
If you are using Unity Pro, and you want to render the cube as shown in the picture (just as a 3D object, no special projection or face mapping), then you would use a RenderTexture, Camera.targetTexture, and Camera.Render()
The Camera.Render() page shows an example with pretty much everything you need, although you may need to play around with culling masks to get the exact effect you want (making sure the render camera sees only the object(s) you want in the final image). Everything can be created and destroyed or reused as needed with this method; it isn’t frame-based, and the actual render will more than likely be incredibly fast.
However, Texture2D.ReadPixels(), Texture2D.Apply(), and Texture2D.Compress() are very slow, and you may need to use yield to spread those calls across multiple frames to avoid a framerate hit if you are trying to maintain 60fps while using this method.
Cheers,
-Adrian