- Home /
Duplicate Question
can we have chance to put 2 actions for single button?
Draw Texture while clicking button in game window, again if I click that button, texture disappear in game window(this type of action for that button goes on throughout the game)?, is it possible?..If any one have code may u plz provide it.
if (GUI.Button (Garland, "Garland"))
{
click=true;
}
if (click == true)
{
GUI.DrawTexture(GarlandRect,Garl);
}
after that what I have to write to disappear texture in game window?
You should be using Unity's "new" UI. Do not use "GUI" for any reason, ever.
Answer by Priyanshu · Mar 22, 2015 at 10:58 AM
What you want is concept of toggling. That is On/Off switch with a single button.
When you press the Button you assign click = true.
Instead assign it as click = !click. Each time you press the button, value of click will switch between true-false.
After that you can write code: If click == true, do this else do that.
Thanks for ur answer, I want toggle condition between textures.I mean whenever I click the button draw some texture, if again I click that button null that texture.
if(click==true) drawtexture; else if(click=flase) null that texture;(off that texture in game window)...(again click it draw,another click null it..)
may u plz give code to null the texture.
All you need to check the material of the object.
if(yourtargettransform.renderer.material != defaultmaterialname)
{
yourtargettransform.renderer.material = defaultmaterialname;
}
else yourtargettransform.renderer.material = paintedmaterialname;
Remember to do this onButtonDown/On$$anonymous$$eyDown so it won't fire every time a frame is painted.
Also remember in Unity 5 you need to
transform.GetComponent<renderer>().material
ins$$anonymous$$d of transform.renderer.material