Button can only be clicked once (Unity) - unity3d

I'm fairly new to this.
When I click on the button to rebind the jump key, the rebind works fine. First the panel "Waiting on rebinding..." pops up, then I press the key, I want jump to be, then the new key shows up on the button as the binding.
This works only once though. When I want to click on the same button again, it doesn't allow me to click on it. The button doesn't even change color anymore, when you hover over it.
What I tried to solve this was to duplicate the button. When I click on either of the buttons and rebind the jump key, it works the first time, but not after that. Both buttons are unclickable. Closing and opening the button panel doesn't work either.
Here is the code for the OnClick() on the button:
public void JumpStartRebinding()
{
startRebindObject.SetActive(false);
waitingForInputObject.SetActive(true);
movement.PlayerInput.SwitchCurrentActionMap("UI");
jumpAction.action.Disable();
rebindingOperation = jumpAction.action.PerformInteractiveRebinding()
.WithControlsExcluding("Mouse")
//.WithCancelingThrough("<Keyboard>/escape")
.OnMatchWaitForAnother(0.1f)
.OnComplete(operation => JumpRebindComplete())
.Start();
}
private void JumpRebindComplete()
{
int bindingIndex = jumpAction.action.GetBindingIndexForControl(jumpAction.action.controls[0]);
bindingDisplayNameText.text = InputControlPath.ToHumanReadableString(
jumpAction.action.bindings[bindingIndex].effectivePath,
InputControlPath.HumanReadableStringOptions.OmitDevice);
jumpAction.action.Enable();
rebindingOperation.Dispose();
startRebindObject.SetActive(true);
waitingForInputObject.SetActive(false);
movement.PlayerInput.SwitchCurrentActionMap("Player");
}

The issue doesn't appear to be with your code. I was having this exact same issue a few days ago. It likely has to do with the fact that a UI object is "covering up" the button. A first step I'd take is making sure that nothing is obscuring your button after re-enabling it (often times, TextMeshProUGUI objects with "Raycast Target" enabled are the culprit).

Related

How to create a menu in unity to purchase ammo for my weapons

I am a student currently creating a zombie FPS game using Unity 3D and I simply want to when I press 'E' on the keyboard, I want a menu to pop up and show the prices of the ammo (I have a pistol9mm and an AK) and when I click on buy, the ammo is purchased and I have more ammo.
Is there any helpful suggestions on how I will approach this scenario please ?
So first and most importantly, you have to create the Menu where you are going to buy the ammo from, make the buttons and then script them in a way that when you press them they take money away from the player and then gives him ammo. A single button "Buy ammo" is enough and just a little panel on which the button should stay is needed. After making the menu work, go to the script where you check if the player has pressed the "E" key. Create a new Game Object which holds the Menu where you buy the ammo from and when checking if the player has pressed the "E" key, check if the menu is opened. If it is not, then open the menu, if it is opened, close it. Here is a simple way of doing it.
public GameObject menu;
private bool isOpen = false;
void Update(){
if(Input.GetKeyDown("E")){ //When "E" key is pressed
if(isOpen == false){ //If the menu is closed, open it
isOpen = true;
menu.SetActive(true)
}else if(isOpen == true){ //If the menu is opened, close it
isOpen = false;
menu.SeyActive(false);
}
}
}
The way it works is, it either sets the menu to active or unactive when you press the "E" key and it's really simple too. Also when you are done with the Menu set it to active so it doesnt apear on the screen when starting the game, just so it will apear after pressing "E" and so players don't have to close it every time.
I hope i helped you, if you have any questions feel free to ask.

BottomSheetDialogFragment- Close only on full swipe Kotlin Android

I have a BottomSheetDialogFragment to show list of items inside a fragment. Each list item got a click event mapped. The problem here is, most of the times click action turns into swipe down action and BottomSheetDialogFragment is getting closed. I have no custom events to monitor the events in my code.
dialog?.also {
it.findViewById<View>(R.id.design_bottom_sheet)?.let { bottomSheet ->
bottomSheet.layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT
BottomSheetBehavior.from(bottomSheet).state = BottomSheetBehavior.STATE_EXPANDED
BottomSheetBehavior.from(bottomSheet).skipCollapsed = true
}
}
I have to prevent the close event of BottomSheetDialogFragment on click action which turns into swipe down action because of small extra movement added. This could happen and needs to handle since this application will be used by general public.
Can anyone suggest to find the swipe distance on BottomSheetDialogFragment. So that if the value is lower, the dialog will remain open. And if the value if high because of intentional swipe event, the dialog will get dismissed.

Wicket AjaxLink javascript handler shows strange behaviour

I have a ListView that displays a list of Panels, one below the other. Every panel features a button (implemented via AjaxLink) that closes the panel and removes it from the list.
This is how the ListView is initalized and how the panels are created:
panelsList = new ArrayList<MyPanel>();
pnlContainer = new WebMarkupContainer("pnlContainer");
ListView<MyPanel> pnlItems = new ListView<MyPanel>("pnlItems", panelsList) {
#Override
protected void populateItem(final ListItem<MyPanel> item) {
item.add(item.getModelObject());
item.add(new AjaxLink<Void>("pnlClose") {
#Override
public void onClick(AjaxRequestTarget target) {
panelsList.remove(item.getModelObject());
target.add(pnlContainer); // repaint panel container
}
});
}
};
pnlContainer.setOutputMarkupId(true);
pnlContainer.add(pnlItems);
add(pnlContainer);
This works so far - the actions that trigger adding new panels (usually also AjaxLinks) do what they should and the new panel is added and displayed correctly. But I have problems getting the close button to fully work.
Please see the following steps:
1) I start the server and navigate to the main page. The ListView is initially populated with one panel.
Close-button-code of this panel:
<a wicket:id="pnlClose" id="pnlClose7" href="javascript:;">Close</a>
Searching the page code for pnlClose7 finds the following javascript code that makes the button work as expected:
Wicket.Ajax.ajax({"u":"./?0-1.IBehaviorListener.0-pnlContainer-pnlItems-0-pnlClose","e":"click","c":"pnlClose7"});;
Note: I do not press the button now, if i would, it would work as expected (thoroughly tested).
2) I trigger an action that opens a second panel. The panel is displayed below the first one as expected.
Close-button of the first panel:
<a wicket:id="pnlClose" id="pnlClosef" href="javascript:;">X</i></a>
Close-button of the second panel:
<a wicket:id="pnlClose" id="pnlClose10" href="javascript:;">X</i></a>
But now, neither searching for pnlClosef nor pnlClose10 finds some javascript code. The buttons (both!) do not work. I can still find the javascript code for pnlClose7.
3) I reload the page via pressing F5.
The button IDs change to pnlClose1a and pnlClose1b. Both IDs have javascript counterparts and work.
4) I press the first button (upper panel, ID pnlClose1a). The panel is closed as expected.
The remaining button's ID changes to pnlClose1c, again without a javascript counterpart. Javascript code for pnlClose1a and pnlClose1b is still present.
To make a long story short, the javascript handlers for my AjaxLinks seem to have shyness issues and only appear after I press F5 or reload the whole page in any other manner. I guess thats because repainting the pnlContainer changes the IDs of the current panels - but why is the linked javascript not updated at the same time? Is there anything I can change in my code to update the whole page without completely reloading it?
Wierd thing is that I am pretty sure this worked before... But I checked the whole class history and can't find any major change that would have triggered that. The ListView-code is mainly static since I added it.
I was had similiar problem. if you have any hardcoded javascript code in your page or panels html file (using <script> tag) remove it and set that js code in renderHead of your panel.

How to programmatically press toolstripbutton down?

I want to push toolstripbutton down in my code and I can't seem to be able to do that. I know on Delphi RAD Studio or XE, you can do the following and cause the button to be pressed.
ToolStripButton1.Down := true;
The only ToolStripButton property I see that comes close to "down" is checked true or false. If I do set it to true, it only highlights the toolstripbutton not press it down.
Here is how the button looks when I put my mouse on it and click:
You can clearly see that the Zoom In button is down.
Here is how the button looks when I try to do the samething through my code by setting CheckOnClick true and Checked true.
In this image, the only thing you can see is the blue box around it. I suppose if I had used just the text on the button, you will see that the whole button filled with blue color to show that it was pressed.
I also have toolstrip button in my other program which acts the same way but I had to use imagelist control to switch between pressed or down or checked verses not pressed or down or checked.
So, is there a way to press the ToolStripButton programmatically in Delphi Prism or C#?
Set the ToolStripButton.CheckOnClick property to True. (It's found in the Behavior section of the Items Collection Editor.)
This makes clicking it just like toggling the Down property in a Delphi TSpeedButton (making it flat or depressed), and if ToolStripButton1.Checked is the equivalent of if SpeedButton1.Down in Delphi.
To set up the test, I did the following:
Created a new Winforms application
Dropped a ToolStrip onto the new MainForm
Added four ToolStripButton items and gave them images to make them easier to see.
Set the CheckOnClick property to True for each of them
Set the Checked property of toolStripButton1 to True;
Added the code below to toolStripButton1.Click
method MainForm.toolStripButton1_Click(sender: System.Object; e: System.EventArgs);
begin
toolStripButton2.Checked := not toolStripButton2.Checked;
toolStripButton4.Checked := toolStripButton2.Checked;
end;
Running the app (initial startup, toolStripButton1 checked and the others unchecked):
The first button is clearly down, and the rest are up.
After clicking toolStripButton1 once:
The first button is now up (unchecked) and the second and fourth are down (checked). (I should pay more attention to the consistency in sizing if I do successive images in future posts.)
If have placed this code in the preceding control in the 'Leave' event.
Private Sub PurposeComboBox_Leave(sender As Object, e As EventArgs) Handles PurposeComboBox.Leave
Me.AppliancesForSelectedFunctionToolStripButton.PerformClick()
End Sub
I do not know if you could place code in Form Load or not.
Hope this helps.

Is there a simple source code viewer plugin for eclipse?

for example
setMediamixDefaultTime(mediamixVO);
boolean booked = false;
Long campaignSeq = mediamixVO.getCampaignSeq();
when I want to know about how to declared setMediamixDefaultTime() method,
I have to jump to setMediamixDefaultTime() declaration line.
It's very annoying especiouly source code is long..
so I need that is,
if I move mouse to that method or keyboard shortcut, the method declaration popup in small window.
just crtl+click on the item you want to jump to.
There is also an outline view, which shows the program structure.
Control + mouse click on the method will take you to the method declartion and you can use the back button to come back to the previous code.
Again the shortcut for back button is Alt + left arrow
You can make use of the Declaration View if you don't want to lose your place, but the Navigate menu's "Last Edit Location", Back, and Forward actions may also work.