Hello, I just wanted to ask about simply way to make ui button as physical kay if it possible because I have a lot of scripts, and objects what I want to use with one ui button, with keyboard there is no problem but I have no idea how to make ui button work as keyboard like getkeydown, getkeyup, getkey. It would be very much easier. I know there is something like event trigger but there I have to add function personally, I have too many scripts with objects what they are prefab. I searched the internet, I could not find an answer
2 Answers
2You could store a reference to your button in code and assign it in the inspector:
public Button myButton;
Then just invoke the OnClick event of that button somewhere:
if(Input.GetButtonDown("SomeButton")) //Check what ever button / key you want on the keyboard
{
myButton.onClick.Invoke(); //Invoke the OnClick event on the button
}
Read more about OnClick here.
Make sure you include UnityEngine.UI at the top of your script.
Just Raycast those buttons
I think what you showed me it is simulating pressing ui button, I want simulating pressing physical key by ui button what would have functions like getkeydown, getkeyup, getkey. Of it is not possible, something like getkeydown(UIbutton), getkey(UIbutton) etc. If I press physical key on keyboard, all scripts what have getkey will react, I dont have to make special functions and references to objects. I really want to uibuttons act like keyboard key.
– WenonAre you calling the functions CameraPosition() at all?
– Llama_w_2Ls