- Home /
Replacing Gui.DrawTexture or gui textures in C#?
Hey, trying to get a script to replace a GUI texture whilst disabling the old GUI texture. Was thinking of using a GUI.BeginGroup to snap all of them together so I don't have to manually change the pos and size.
Just wondering if there is any bit of code at all that will replace the GUI? or how to disable/enable GUI without disabling the gameobject
Can you show the bit of code where you are drawing the texture? I'm not sure exactly how you are implementing at the moment, but I'm sure there's a simple solution.
Because I have different textures I want to replace.
Example;
1 texture for 90, 80, 70, 60. (Because they're changing colors for how much health you've got. But this is what I've got at the moment. public Vector2 pos = new Vector2(20, 40); public Vector2 size = new Vector2(40, 20);
public Texture2D background;
public Texture2D texture2;
public Texture2D texture3;
public float barDisplay;
// Use this for initialization
void OnGUI()
{
UnityEngine.GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
UnityEngine.GUI.DrawTexture(new Rect(0, 0, size.x, size.y), background);
UnityEngine.GUI.BeginGroup(new Rect(pos.x, pos.y, size.x * barDisplay, size.y));
UnityEngine.GUI.DrawTexture(new Rect(0, 0, size.x, size.y), texture2);
UnityEngine.GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
UnityEngine.GUI.DrawTexture(new Rect(0, 0, size.x, size.y), texture3);
UnityEngine.GUI.EndGroup();
UnityEngine.GUI.EndGroup();
UnityEngine.GUI.EndGroup();
Doesn't work so well.
Why don't you just put some conditionals in there?
if(some condition)
{
GUI.DoWhatever();
} else {
GUI.DoSomethingElse();
}
that's all good and stuff, but I don't know how to disable a GUI texture which is what I was kinda asking. :/
But my point is that you can't 'disable' them, since they get redrawn every frame anyway! All it takes is just not redrawing them- hence if statements. I still don't understand what you mean by 'disable a GUI texture'- it's not a statement that makes sense to me. It only makes sense for GUITexture components, and you're not using one of those.