- Home /
Material is blending with background problem
I'm making a healthbar by using a material and Graphics.Drawtexture. My material has the 'Transparent/Cutout/Diffuse' shader to make the healthbar cutoff whenever the player looses health. Now I'm having this issue where the healthbar blends with the background instead of displaying it as a solid bar. I must have something to do with the blendmode I guess, but I have no idea how to change that. So how can I fix this? Here's a screenshot: http://i62.tinypic.com/2ptbig2.jpg
For the texture I use a red texture with a black and white gradient as an alpha channel.
I tried to use a plain red texture without alpha channel and a material with the 'Diffuse' shader to test it, but I get the same result.
Here's the code
public class Interface : MonoBehaviour
{
public Texture2D healthBarTex;
public Material healthBarMat;
public float hitPoints;
private GameObject player;
void Awake()
{
player = GameObject.Find("Player");
}
void OnGUI()
{
hitPoints = player.GetComponent<Health>().hitPoints;
if (Event.current.type.Equals(EventType.Repaint))
{
Graphics.DrawTexture(new Rect(0, 25, 500, 100), healthBarTex, healthBarMat);
healthBarMat.SetFloat("_Cutoff", 1 - (hitPoints / 100));
}
}
}
Wait, you're getting the same problem with the standard Diffuse shader? It doesn't have a blendmode -- it isn't transparent. The problem can't be in your material if you get it without using your material.
Could be the background has some crazy blend setting?
Is there a way I can check the blend settings? I just tried it out in a different scene with nothing but a camera and some planes with no textures and the same happens..
why don't you use unity's new UI System ? it's a lot easier and much more COOL ;) use Filled Images Image and i think you should double check your material for the GUI too
Well at this point scripting the UI is easier for me but I just tried out the new UI system for the first time. I don't know why, but when I add the healthbar material to the image it just becomes invisible?
Your answer
Follow this Question
Related Questions
Unity3D texture2d error help 0 Answers
Graphics DrawTexture C# Does not appear 1 Answer
Graphics.DrawTexture not working after changing quality settings 1 Answer
GUI.DrawTexture versus Graphics.DrawTexture 4 Answers
Graphics.DrawTexture + GUI.color 0 Answers