- Home /
 
Tile and offset a Texture2D?
I have a sprite sheet with a bunch of different items I want to use similar to minecraft's. I need to tile and offset my sprite sheet so I can get each one of these items in the texture. The problem is that I need to do this for a Texture2D but I don't think that's possible because you can't tile or offset a texture represented as a Texture2D. So my question is how do I get around this problem, how do I tile and offset a texture that can be applied to a GUI for a HUD?
Thanks.
Answer by Ipsquiggle · Sep 07, 2011 at 02:31 AM
It is not possible to do either tiling or subtexturing (picking a region out of a larger texture) using UnityGUI. If you really need this, consider using a 3rd party GUI system, or make your own using textured quads aligned to a camera. Then you will be able to access either the material (as suggested in IllogicalIronical's answer) or the UVs of the quad in order to do subtexturing.
Answer by Illogical-Ironic · Sep 06, 2011 at 03:02 AM
I know how. I have this code that might come in handy:
 var texture : Texture2D;
 var scaleX : float = 1.0;
 var scaleY : float = 1.0;
 var offsetX : float = 0;
 var offsetY : float = 0;
 
 function Start() {
     // Create a new texture and assign it to the renderer's material
     renderer.material.mainTexture = texture;
 
     //Set the texture to the indicated offset
         renderer.material.mainTextureOffset = Vector2 (offsetX, offsetY);
 
     //Change the scale of the texture
     renderer.material.mainTextureScale = Vector2 (scaleX,scaleY);
 }
 
               I hope it helps you as well as it helped me out :D
No that's not what I'm looking for I need to tile a texture2D, not a material.
Your answer
 
             Follow this Question
Related Questions
Offset detail texture in c# 1 Answer
more guitexture in void ongui 1 Answer
Assiging an Image to a Button 1 Answer
Best way to show an image 2 Answers
GUI texture to change texture when hovered over or clicked? 2 Answers