Hey im new to unity and c# and am wondering how i simulate a keypress.
so what i want is when i click button 1 it send keypress a to the program.
does anybody have a script for this?
thanks in advance
-worthypro
Keypresses in Unity don’t do anything, except what you program them to do. So, the button can “simulate a keypress” by doing whatever that keypress does.
What exactly is it that you expect to happen when this key is pressed?
1 Like
In the below simple example, in the UI button’s OnClick event add JumpUIButtonPressed(). Then when the user presses that UI button it does the same thing as pressing the spacebar.
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space))
{
jump();
}
}
private void jump()
{
//code related to jumping here
}
public void JumpUIButtonPressed()
{
jump();
}
2 Likes