Texture on one face of a cube

Hey everyone,

I'm trying to figure out how to texture one side of a cube. I first tried to make the cube really thin and did a transparent diffuse on it but occasionally you can see pixels on other sides.

Also, is there a better easy way to get the illusion of an animated 2D Sprite than putting the animated texture on the side of a cube?

thanks!

No point in "faking" a sprite with a cube. Just use a plane instead. It only has one polygon.

UV map the cube the way you want in a 3D app. For a sprite, it would be better to put it on a quad, either made procedurally or in a 3D app.

Get a 3D application, like 3Ds Max, Blender for free.

UV map it (www.google.com), and then you want to apply the texture as the UV map... Then you can alter it that way.

What about adding quad/plane inside of cube, set the position and texture it?

This shader will work for this

Shader "Custom/CubeSurfaceShader"
{
 Properties {
        _MainTex ("Texture", 2D) = "white" {}
        _Face1 ("Face 1", 2D) = "black" {}
        _Face2 ("Face 2", 2D) = "black" {}
        _Face3 ("Face 3", 2D) = "white" {}
        _Face4 ("Face 4", 2D) = "white" {}
        _Face5 ("Face 5", 2D) = "white" {}   
        _Face6 ("Face 6", 2D) = "white" {}
        _BorderSizeF1 ("Border Size Face 1", Range(0, 0.5)) = 0
        _BorderSizeF2 ("Border Size Face 2", Range(0, 0.5)) = 0
        _BorderSizeF3 ("Border Size Face 3", Range(0, 0.5)) = 0.03
        _BorderSizeF4 ("Border Size Face 4", Range(0, 0.5)) = 0
    }

    SubShader {
        Tags {"RenderType"="Opaque"}
        LOD 100

        Pass {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float2 uv : TEXCOORD0;
            };

            struct v2f {
                float2 uv : TEXCOORD0;
                float3 normal : TEXCOORD1;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            sampler2D _Face1;
            sampler2D _Face2;
            sampler2D _Face3;
            sampler2D _Face4;
            sampler2D _Face5;
            sampler2D _Face6;
            float _BorderSizeF1;
            float _BorderSizeF2;
            float _BorderSizeF3;
            float _BorderSizeF4;

            v2f vert (appdata v) {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                o.normal = v.normal;
                return o;
            }

            float4 _MainTex_ST;

            float4 frag (v2f i) : SV_Target {
                float4 col;
                if(i.normal.z > 0.999) {
                if(i.uv.x > (1.0 - _BorderSizeF1) || i.uv.x < _BorderSizeF1 || i.uv.y > (1.0 - _BorderSizeF1) || i.uv.y < _BorderSizeF1)
                    col = float4(0,0,0,1);
                else
                    col = tex2D(_Face1, i.uv);
            }
            else if(i.normal.z < -0.999) {
                 //flipping face 3 texture so that it is orientated the same as sides 1,2&4
                float2 uv = i.uv; 
                uv.x = 1.0 - uv.x; //flip texture in the X
                uv.y = 1.0 - uv.y; //flip texture in the Y
                if(i.uv.x > (1.0 - _BorderSizeF3) || i.uv.x < _BorderSizeF3 || i.uv.y > (1.0 - _BorderSizeF3) || i.uv.y < _BorderSizeF3)
                    col = float4(0,0,0,1);
                else
                    col = tex2D(_Face3, uv);
            }
            else if(i.normal.x > 0.999) {
                if(i.uv.x > (1.0 - _BorderSizeF2) || i.uv.x < _BorderSizeF2 || i.uv.y > (1.0 - _BorderSizeF2) || i.uv.y < _BorderSizeF2)
                    col = float4(0,0,0,1);
                else
                    col = tex2D(_Face2, i.uv);
            }
            else if(i.normal.x < -0.999) {
                if(i.uv.x > (1.0 - _BorderSizeF4) || i.uv.x < _BorderSizeF4 || i.uv.y > (1.0 - _BorderSizeF4) || i.uv.y < _BorderSizeF4)
                    col = float4(0,0,0,1);
                else
                    col = tex2D(_Face4, i.uv);
            }
            else if(i.normal.y > 0.999) col = tex2D(_Face5, i.uv);
            else if(i.normal.y < -0.999) col = tex2D(_Face6, i.uv);
            else col = tex2D(_MainTex, i.uv);
                
                return col;
            }
        ENDCG
        }
    }
    FallBack "Diffuse"
}