If the player goes too far on the x axis, it will be out of bounds and will have to retry the level. The purple grid symbolizes the x limit of the level. It is actually a simple plane stuck on a certain x value but follows the y and z positions of the ball. To give the impression that the grid is “infinite”, I’ve attached to my plane a script changing the offset of the texture depending on the y and z positions of the ball. It works fine, but the square shape of the grid is not so aesthetic.
The plane with the grid uses the Transparent/Cutout/SoftEdgeUnlit for the following reasons :
The material.color.a changes depending on the distance between the ball and the grid, making it dissapear if the ball is too far, so I need a material with the “Color” component ;
Both sides are visible ;
I need a material which understand the alpha channel of my .png file.
How could I have this result, knowing that the _MainTex (and its own alpha channel) offset depends on another object ?
There is probably an error, when I select your shader in the inspector, I can’t add any texture to the “Alpha mask” property. It continues saying “None” (Texture). The console tells me :
Material doesn’t have a texture property ‘_AlphaTex’
UnityEditor.DockArea:OnGUI()
And even with a texture in the Base (RGB), my mesh keeps this annoying pink colour.
Sorry about these questions that could seem absurd, I’m not really good at coding shaders, especially in csharp.
I don’t know how will look my grid when I’ll manage to use your shader, but I would also need the “Color” property (as I said I change the renderer.material.color.a depending on the distance between the ball and the grid) and an alpha mask directly in the “_MainTex” property (or the squares between the grid lines will be opaque).
NB : I forgot to mention, but as you can see it in my screenshot I’m using the free license of Unity. Could it be a limitation problem ?
Shader "Custom/Map Borders" ////////// Shader renamed
{
Properties
{
_Color ("Mask Color", Color) = (1, 1, 1, 1) ////////// _Color property added to this shader
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Cull Off ////////// I added this line to have the both sides of my plane mesh visible
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {
constantColor [_Color]
Combine texture * constant ////////// The alpha component of the _Color property defines the Culling Mask opacity (depending on the distance between the player and the grid)
}
SetTexture [_MainTex] {combine texture, previous}
}
}
}
Now it works fine, here’s a fresh new screenshot with my problem solved :
Hi, could you please explain further on how you do it? I want to do something similar as well. But I still did not understand about it. Sorry, unity3d newbie here. Thanks.