- Home /
2D Sprite Fillup without using UI
I have been trying extensively to find a way to allow a fill-up bar without having to use UI. My image for my game is to be able to watch the health of an enemy diminish over its head while attacking it, hit by hit. The one problem with this is that it appears to be impossible. Or so I think. I cant seem to find a way to do this and I've been playing with options extensively. Worst comes to worst, I just make the center of the image on the far left side and decrease the horizontal size throughout every update. But that seems very un-efficient. Any ideas?! Heres a picture below to represent my idea:
Currently I'm going with the option i decided beforehand by changing the texture to originate from the left side so the bar declines incrementally, however I would still like an actual fix to this rather than changing the scale....
Answer by game4444 · Aug 30, 2017 at 04:50 AM
I have attached a shader for the solution of your problem. You have to make a material and give this custom shader to that material. Select your material on your health bar sprite. You will get the option of fill value. then use that value accordingly. One thing you have to check shader may work in vertical not horizontal. If that problem comes open shader file and check x and y. Try to replace them and check. shader
It works, I'll just rotate the sprite ins$$anonymous$$d. I appreciate your help and I did test it for a second but haven't added it to my script just yet. This really is a life saver. I looked everywhere for this and still couldn't find it. I don't understand why something like this isn't in unity by default. Thank you so much....
It's been a couple years, but going back to using this shader, I'm trying to figure out a way to have it work simultaneously with code. Something like HealthDisplayer.GetComponent(). that allows me to edit the fillup value would be great. or anything along those lines
edit: I figured it out! https://answers.unity.com/questions/340937/how-to-change-a-value-in-custom-shader-through-scr.html
Your answer
Follow this Question
Related Questions
How to sync animation if animation should be use with specially object 0 Answers
What is the best/easiest way to align a 2D rigidbody to specific sections of a sprite? 1 Answer
Help Me! I want to make a pixel fairy! 1 Answer
Pixelart distorts on import. 1 Answer
,Spawning snow or changing tilesets to snow as the player walks past them 0 Answers