How to disable the UGUI button component? - unity3d

I used the
GetComponent<Button>().interactable = false;
to disable the button component, but find the UI gameobject become transparent. And I just want disable the button without changing transparent, just like remove the tick on button component.
Did I use it wrong? Or is there something else to do it?

GetComponent<Button>().enabled = false;

Related

UI Button doesn't disappear when deactivating parent in hierarchy

I'm trying to write a simple main menu page with this hierarchy:
MainMenu (an empty game object)
↳ Canvas
↳ PlayButton (a TextMeshPro Button)
I want the button to deactivate the 'MainMenu' object in the hierarchy when clicked, thus hiding its Canvas child and the Button along with it. To do this, I'm providing the MainMenu object reference to the Button's OnClick() callback and calling 'GameObject.SetActive' to false when clicked.
My problem is that when I click the button, the MainMenu hierarchy get grayed out in the editor but the Button sticks around with its yellow Highlighted color shown. It does disappear if I change the display resolution while still in Play mode (maybe forcing a refresh?), but I can't figure out why deactivating the MainMenu wouldn't make it refresh in the same way.
I've tried calling SetActive(false) on the PlayButton and the Canvas themselves- I also tried setting enabled = false on them, but the Button appearance behaves the same. From everything I've read, calling SetActive(false) should hide whatever gameObject I call it on, so I can't figure out what I'm missing.
Alright, found my own mistake. The Camera's Clear Flags setting was Don't Clear, so even calling Destroy(gameObject) on it didn't remove it from the screen.
Setting the Camera to use ClearFlags: Solid Color fixed the problem.
It looks to me like you have a button in your grid that is displaying. When the game is playing, after you click to turn off the button, go to the scene tab, click the yellow button and see where that object is.
If in doubt (For testing purposes only) delete the button on click and if you see something else then it is obviously not that button.

How to auto hide panel when click other button in Unity

I'm currently working on a Solar System AR for my final year project.
I created a menu with a button of 9 planets. For example, when I click on Sun button, there's an information panel open along with a 3D Sun. And then, there's a close button to close the panel.
But the problem came when I clicked all the 9 buttons, the 3D and the information panel overlapping each other and I have to close it manually using close button one by one, which is quite nuisance.
Therefore, is there any ways to auto hide/close panel when the other buttons is clicked. Note that I'm a beginner in Unity and not so good with coding. I would appreciate so much if you could left any tips.
Yes, this is fairly easy!
For example, go to the "Sun" button and in the Button Component you will find On Click()
Add (+) the amount of GameObjects or "Panels" you want to hide when clicking on other buttons.
Once you add them all, choose from the drop down menu on the right GameObject.SetActive and make sure the box below is set to false.
This way, whenever you click on any of the planets, the others will be de-activated.
Alternatively, you could also invoke a method that sets those panel's Alpha to 0 and disable their Raycast if you don't want to deactivate them.
There is no code showing us how you open the panel window.
But one way to achieve what you want is to only have one panel window at all, and only change the text depends on the previous clicked planet.
Here is one example :
public class PlanetDisplayer : MonoBehaviour
{
private bool isOn = false;
[SerializeField] private Image planetImage;
[SerializeField] private Text planetText1;
[SerializeField] private Text planetText2;
private void OnClick(Planet planet)
{
planetText1.text = planet.MainText;
planetText2.text = planet.AnotherText;
if (!isOn)
{
isOn = true;
gameObject.SetActive(true);
}
}
private void OnClose()
{
isOn = false;
gameObject.SetActive(false);
}
}
So, planetText and planetImage are examples, as I can see on your picture, there is some texts and I guess a picture for the name.
You can attach this class on the panel GameObject, and it will override the text on each click. This way you won't have to close every single panel window. There is only one.
Don't forget to link private text variables (and image, if any) in the inspector.

keep arrow visible fancybox

In the photo gallery of Fancybox, the slide show has arrows disappearing and reappearing when moving the mouse.
I want the arrows to remain visible. I used
.fancybox-nav span {
visibility: visible;}
but no result.
You can use idleTime option to change idle time or to disable completely -
$.fancybox.defaults.idleTime = false;

NGUI UIToggle how to toggle / deactivate one

I have two UIToggle objects, so when I click on, for example, toggle 1 it enables itself and toggle 2 becomes disabled. But I am trying to toggle them in the script.
I get the UIToggle 1 like this:
UIToggle toggleOn = ToogleParen.transform.FindChild("ButtonOn").GetComponent<UIToggle>();
And activate it doing this:
toggleOn.value = true;
The problem becomes when I try to deactivate it:
toggleOn.value = false; <--- does nothing, the toggle button does not deactivate!!
Does anyone know how to toggle two UIToggle objects programmatically?
Thank you!!
You will have to refresh the control so that NGUI redraws it on the screen. Just like you have to do incase of a grid after adding certain items.
BONUS:
By what you have described I think you want to achieve something like radio buttons (only one selection is possible at a time). If yes, then you should use UICheckbox as NGUI provides features to use checkbox as a radio button and i this case you won't have to uncheck other checkboxes in the code.

How to make a button in android and make it invisible

I want to have a button which should not be visible but when clicked onclick should be executed..
I have tried making
Button button;
1)button.setVisiblity(4);//it made it invisible but onclick was not working
2)In the layout xml i have attached android:visibilty="invisible" //but it made it invisible
Remove the visibility bit and use the following instead.
button.setBackgroundColor(Color.TRANSPARENT);