- Home /
Create an outline around GUITexture
Hi, I have a GUITexture of a key in my HUD, i'd like to outline it with a color when the player can press this key.
Answer by Owen-Reynolds · May 10, 2013 at 04:10 PM
The standard approach (all games, not just Unity) is to build three textures: normal, hover (the outline you want) and pressed. The artist may just paint an outline around Normal to make Hover, but in Unity it counts as an entirely different texture.
If you look at GUIStyles, they have the same system -- slots for normal, hover and active (being held down.)
In your code, you'd do something like (very crude):
public Texture2D norm1, hover1, pressed1; // drag textures into inspector
if(mouse in button area)
B1.guiTexture.texture = hover1;
else
B1.guiTexture.texture = norm1;
The other method is to make a larger GuiTexture under the button (smaller z value.) The turn it on/off (SetActive(true)?) to make the border. But the first method looks nicer (the whole button can change a little, not just get an edge.)
Your answer
Follow this Question
Related Questions
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Disable a object 1 Answer
iPhone GUI Texture (TouchPad prefab) not working 2 Answers
ReadPixels requires an offset while in the Editor? 2 Answers
Renderer Texture on GUITexture 1 Answer