- Home /
Fill a Circular Progress Bar Based on Value
Hi,
Edit: I need to fill up a circle texture with another texture (apparently a material) based on a value. I have two Texture varaibles, 'rightCircle' and 'backgroundTexture'. I have a material texture 'mat' of which is a transparant/cutout/diffuse shader. public Texture backgroundTexture, rightCircle; public Material mat;
void OnGUI() { if (Event.current.type == EventType.Repaint) { mat.SetFloat("_Cutoff", Mathf.InverseLerp(0, 48, someScript.growVar);
Graphics.DrawTexture(new Rect(987, 0, 58, 45), backgroundTexture, mat);
Graphics.DrawTexture(new Rect(987, 0, 58, 45), rightCircle);
}
}
EDIT -- The above draws a square (alpha) with the image of a circle in the middle of the square. [o] <-- kind of like that, but with the top and bottom width's drawn in. Each time that someScript.growVar increments, a little portion of the square dissapears...but instead of the square (alpha) being drawn, I need it to be a circle.. :-/
rightCircle
is just to show a border for the circle, right? (try removing it for now); the materials mainTexture..try meddling with that; edit you post to include an image of atleast what you see as that "[0]" is pretty fuzzy atleastforme8-)
I agree, How can I upload a pic? I'm also getting run time errors for the Graphics.DrawTexture() function has mat as one of its paramaters.
thought it would be simple; I'd comment out lines till it's working again, DrawTexture()s, Event stuff, someScript referencing or meddle with the mat; sry can't seem to help more :/
Answer by matyicsapo · Aug 27, 2010 at 09:15 PM
have you tried looking around? maybe this related question might help? http://answers.unity3d.com/questions/7449/creating-a-circular-progressbar-timer the alpha texture idea is i guess what you need too
create a material, set it's shader to transparent cutout and prolly diffuse, for the main texture use a texture use sg. like the one in the above link where white parts represent fully opaque, or as mine
if you go with a textured object, a plane for example use sg. like the following code from Update() prolly
renderer.material.SetFloat("_Cutoff", alphaCutoff);
but I assume you wanna stick to GUI so you could do sg. like this:
void OnGUI () {
if (Event.current.type == EventType.Repaint) {
mat.SetFloat("_Cutoff", alphaCutoff);
Graphics.DrawTexture(screenRect, texture, mat);
}
}
check out the documentation for Graphics.DrawTexture() - the reason for the event fuss
in both cases the alphaCutoff
is the float value you'll alter based on your (game)logic
(using the above pic for the alpha texture I have some bugs and artifacts(not the one that it's upside-down))
Thanks for the reply, I have seen that post, but I have idea how to implement it into the above code! The documentation has a varaiable defined as "paramater" which to me suggests that the inv. lerp function goes in as the width?
I need to reference the renderer.material.SetFloat() via a texture to get it to work probably...
..you wanna fill up a circle with a texture based on a value? draw the circle and then the filling texture with it's alpha so it doesn't go out of the circle..might have misunderstood you somewhere sry
I used your code which you were so kind to provide, but I am not seeing the background texture being drawn within the circle..It is still a square shape fill. --Edited post
I'm having an issue where the texture when drawn to the screen (using the DrawTexture method) is appearing as all black and not as its correct color (green). The material I'm using has the texture render when placed on a plane in the world, but not when drawn with a GUIscript.