Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feature Request Input Priority

Discussion in 'Input System' started by Cosser_Production, Oct 22, 2023.

  1. Cosser_Production

    Cosser_Production

    Joined:
    Sep 13, 2019
    Posts:
    5
    I'm programming a little game for Android where the player jumps as soon as I press the button (from the project using the mouse button) and I also have a UI button on the screen which would be the pause button, the problem is that when I press the pause button the player jumps and then the pause occurs, and i don't want that the player jump first , is there a priority management of events? Is there a way to avoid checking if the inputs are squashed in certain areas of the screen? How would you handle this problem?
    Thank you!
     
  2. Deleted User

    Deleted User

    Guest

    Please, post your code for both the button and your player, using code tags. Thank you.
     
  3. Cosser_Production

    Cosser_Production

    Joined:
    Sep 13, 2019
    Posts:
    5
    The Button is a classic UI Button where in the ispector you have the On Click() that you need to add the script and the function associated , in this case GameManager.cs -> TogglePause()

    GameManager script
    Code (CSharp):
    1. private void DisableEnableAll()
    2. {
    3.     //Unity non selezionava gli oggetti inattivi , con questo metodo invece si
    4.     GameObject[] y = Resources.FindObjectsOfTypeAll<GameObject>();
    5.     foreach (GameObject element in y)
    6.     {
    7.         if (element.transform.parent != null) continue;
    8.         if (element.name == "Main Camera") continue;
    9.         if (element.name == "Pause") continue;
    10.         if (element.name == "GameManager") continue;
    11.         if (element.name == "EventSystem") continue;
    12.         element.SetActive(!inPause);
    13.     }
    14.  
    15. }
    16. public void TogglePause()
    17. {
    18.     inPause = !inPause;
    19.     DisableEnableAll();
    20.     pauseButton.SetActive(!inPause); pauseMenu.SetActive(inPause);
    21. }
    PlayerControllerScript:
    Code (CSharp):
    1. void Update()
    2. {
    3.     this.transform.position = new Vector3(this.transform.position.x + Speed * Time.deltaTime, this.transform.position.y, this.transform.position.z);
    4.     if (Input.GetMouseButtonDown(0)&&Ground)
    5.     {
    6.         rb.AddForce(new Vector3(0, JumpForce, 0),ForceMode.Impulse);
    7.         Ground = false;
    8.     }
    9. }