Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by baukjespirit · Feb 24, 2015 at 02:05 PM · graphicsblendingdrawtexturematerial renderer

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));
         }
     }
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Feb 24, 2015 at 04:19 PM 0
Share

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?

avatar image baukjespirit · Feb 24, 2015 at 04:32 PM 0
Share

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..

avatar image Sleepfree2014 · Feb 24, 2015 at 05:38 PM 0
Share

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

avatar image baukjespirit · Feb 25, 2015 at 12:19 PM 0
Share

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?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges