• Advertisement
Sign in to follow this  

Graphics.DrawTexture not displaying properly?

This topic is 1097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Maybe a basic question, but I couldn't find an answer on google.

I'm making a healthbar in Unity C#, and I'm using Graphics.DrawTexture to display the healthbar, but for some reason the texture is blending with the background. The material uses the 'Transparent/Cutout/Diffuse' shader.

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));
        }
    }
}

And a screenshot:

vzy0sg.jpg

Edited by BaukjeSpirit

Share this post


Link to post
Share on other sites
Advertisement


The material uses the 'Transparent/Cutout/Diffuse' shader.

I think you've answered your own question.

Share this post


Link to post
Share on other sites

 


The material uses the 'Transparent/Cutout/Diffuse' shader.

I think you've answered your own question.

 

I don't really see the problem? I'm using a texture with a black and white gradient as an alpha channel:

vzwvab.png

 

The material looks like this in the inspector:

16a6s6u.jpg

 

I used this technique once in the past and had no problems with it then.

Share this post


Link to post
Share on other sites

Then it sounds like something you've drawn elsewhere has changed the blend mode or something similar without setting it back.

Share this post


Link to post
Share on other sites

Then it sounds like something you've drawn elsewhere has changed the blend mode or something similar without setting it back.

Is there a way to check/change the blend mode? Because I have no clue where I could've drawn something that might have changed it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement