K
K
KirillSystem2022-04-18 13:00:36
Unity
KirillSystem, 2022-04-18 13:00:36

How to create touch button Escape in Unity?

Good afternoon, I'm creating a game on Unity, I created a pause, it opens with the help of Escape by script.

I want to make it so that the Escape button is pressed using the UI button and I have already rummaged through the entire Internet in the hope of finding at least some kind of tutorial.

My goal is to make the touch button emulate pressing the standard escape button when pressed with a finger

How to do this?

And if possible, show the script how to do it

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mimocodil, 2022-04-18
@Ezekiel4

Move the implementation of the pause into a separate public method. Then open your UI Button and scroll down in the inspector until you see the On Click field, just below it there will be a + button, click. The following scheme will appear:
625d3da8287f0344210173.png
In the lower left field, drag the object on which the script hangs with a pause. Then, in the dropdown on the top right, select your pause class and method.
You asked for the code, it will look like this. Before:

private void Update() {
  if (Input.GetKeyDown(KeyCode.Escape)) {
    // your code
  }
}

After:
private void Update() {
  if (Input.GetKeyDown(KeyCode.Escape))
    OnPauseStart();
}

public void OnPauseStart() {
  // your code
}

PS. If you want, you can try to put a function on the back button
private void Update() {
    if (Application.platform == RuntimePlatform.Android) {
        if (Input.GetKeyDown(KeyCode.Escape)) {
      // your code
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question