Hi, I have problem with getting two buttons to work on my menu. Buttons are left and right arrows that should change the panel on the canvas. buttons are making sound and when panel reach the edge of canvas left or right button.setActive is turn on. I got this to working with “Fire2” as left and “Jump” as right.
How would i get my buttons instead of “Fire2” and “Jump”?
Code looks like this:
void Update() {
ShowLeftButton();
ShowRightButton();
if (Input.GetButtonDown("Fire2")) // press alt to -2000f SHOULD BE "SlideLeft" for now is Fire2 which is alt
{
if (slidePanel.anchoredPosition == new Vector2(5453.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(3453.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(1453.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(-547.0f, -365.0f))
{
slidePanel.anchoredPosition = slidePanel.anchoredPosition + slideLeftAmount;
}
}
if (Input.GetButtonDown("Jump")) // press space to +2000f SHOULD BE "SlideRight" for now is Jump which is space
{
if (slidePanel.anchoredPosition == new Vector2(-2547.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(-547.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(1453.0f, -365.0f) ||
slidePanel.anchoredPosition == new Vector2(3453.0f, -365.0f))
{
slidePanel.anchoredPosition = slidePanel.anchoredPosition + slideRightAmount;
}
}
}
Okay, so for UI buttons, what you want to do is:
First, create 2 methods (1 for each of the code you have now with GetButton), and make them public.
Then, remove the Update code about the buttons you have now.
Next, add an event to each button (OnClick event → little plus sign)
Drag the game object with the script onto the game object of the OnClick event.
Use the dropdown menu for the On-Click event, and select the method Repeat that for the other button.