- Home /
Draw.texture behaving weird.
Hello, i have a simple health bar script, that uses a 2D texture and a material with shader Transparent/Cutout/Diffuse. The texture is alpha transparent. I'm using Draw.texture to display the healthbar. The health bar should look like this -
But depending on the cameras position, it seems to change into this -
I've also noticed that, the way the second image looks depends on how bright ambient light is.
Can i do that the Draw.texture function wouldn't use ambient light or something? Or am i just doing the whole thing wrong? Code : void Start () { HealthScript HS = GetComponent<HealthScript>(); MaxHealth = HS.Health + (float)0.1; mat = new Material (Shader.Find ("Transparent/Cutout/Diffuse")); mat.mainTexture = HealthBarTexture; } void OnGUI () { if(Event.current.type.Equals(EventType.Repaint)){ //Is the game being drawn? Rect box = new Rect(Screen.width * x ,Screen.height * y,Screen.width * w,Screen.height * h); Graphics.DrawTexture(box, HealthBarTexture, mat); } }
You are using a Diffuse shader, which reacts to light. Use a different shader.
Your answer
![](https://koobas.hobune.stream/wayback/20220613150934im_/https://answers.unity.com/themes/thub/images/avi.jpg)