Answer the question
In order to leave comments, you need to log in
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
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:
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
}
}
private void Update() {
if (Input.GetKeyDown(KeyCode.Escape))
OnPauseStart();
}
public void OnPauseStart() {
// your code
}
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 questionAsk a Question
731 491 924 answers to any question