- Home /
change Texture2d colors?
Hello. I am using this code for a load bar
private var barDisplay : float =.5 ;
var barHealspeed : float = .02;
private var pos : Vector2 = new Vector2(278,438);
private var size : Vector2 = new Vector2(123,14);
private var progressBarEmpty : Texture2D;
private var progressBarFull : Texture2D;
function OnGUI () {
switch (currentPage) {
case Page.Page1: Page1(); break;
case Page.None: None(); break;
}
}
function Page1 () {
// draw the background:
GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
//GUI.contentColor = color.yellow;// change text
//GUI.backgroundColor = color.blue; // change button color
//GUI.color = color.green; // change text color
GUI.EndGroup ();
GUI.EndGroup ();
I've tried using the GUI.color codes up above to change colors, but they don't change the texture2d colors. Is there a way to change the bar's colors? And if so, then how do I plug it in? It's a bother because right now it is a dark gray color, and when it turns to night in my game or I am in dark area, you can't see the bar. I have two bars like this, and one I use for elemental attacks, the other is a force attack load bar. I really need to be able to change their colors specifically. Thanks for any help!
Answer by sven1994 · Aug 01, 2011 at 07:58 PM
You can change single pixels or blocks of pixels using the Texture2D functions (especially SetPixels, GetPixels), but I think for a progress bar there are much better solutions.
I have no idea how they set that up in the docs, let alone how to apply the examples they gave to the code I am working with. Could you please provide an example? Why doesn't the load bar just change colors with the rest of buttons/texts with Gui.color commands anyway? Isn't the bar a gui built item?