- Home /
Can I have a virtual area to act as a button?
Hello,
I am developing for android, I have GUItextures acting as buttons.. However I need at some places to select a virtual area to be a separate button. For now I am importing the button area(png) as a different guiTexture.
please check the picture! Thanks
for example, I have the close button as a separate layer in photoshop.. but if i could select my desired area to act as a button. (of course appearing only in the scene view) check the second picture plz
D'you mean you wish to have a transparent area act as a button?
Check my answer here : http://answers.unity3d.com/questions/377430/mul$$anonymous$$ch-area.html
Answer by GuyTidhar · Mar 18, 2013 at 01:45 PM
Use a button and set with with a transparent png (original size of 2x2 so it'll be small)
do you mean a gui.button? and that will have the default button display ..
I mean a GUI button (ok if you don't need many).
But ins$$anonymous$$d of using the default GUI look, you set the normal and hover images to the transparent png I've mentioned.
You can work with GUIStyle:
public Rect yourClickableArea = new Rect (0,0,200,200);
public Texture2D yourEmptyImage;
void OnGUI()
{
GUIStyle guiStyle = new GUIStyle();
guiStyle.normal.background = yourEmptyImage;
guiStyle.hover.background = yourEmptyImage;
if ( GUI.Button(yourClickableArea, "", guiStyle) )
{
// Stuff to do
}
}
You could also work with GUISkin if you are familiar with it. Basically you do the same thing by using it, since GUISkin holds a gui button style or your custom one.
Answer by MrSteve1 · Mar 18, 2013 at 02:09 PM
You can just make a transparent image and place that right where you need it.
Answer by PAHeartBeat · Mar 18, 2013 at 04:20 PM
you also can use just invisible rect like that
Rect invisibleButton = new Rect(0,0,100,100);
void Update(){
if(invisibleButton.Contains(input.GetMosuseUp(0)){
// do somithing
}
}