Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can i split screen with Screen.width and Screen.hieght for touch input using new input system?

Discussion in 'Input System' started by SamiRehman1997, Sep 19, 2023.

  1. SamiRehman1997

    SamiRehman1997

    Joined:
    Aug 13, 2018
    Posts:
    74
    I want to move my play using the position of the touch on the screen as shown in that picture I was doing this by using
    Code (CSharp):
    1. private int splitScreenX = Screen.width / 2;
    Code (CSharp):
    1. private int splitScreenY = Screen.height / 2;
    with legacy input system for detecting touch I was using
    Code (CSharp):
    1. Input.GetMouseButtonDown(0)
    . Here is this full code

    Code (CSharp):
    1. private int splitScreenY = Screen.height / 2;
    2. private int splitScreenX = Screen.width / 2;
    3.  
    4. void Update()
    5. {
    6.     RunModeInput();
    7. }
    8.  
    9. void RunModeInput()
    10. {
    11.     if (Input.GetMouseButtonUp(0))
    12.     {
    13.         if (InputManger.Instance.isStarted)
    14.         {
    15.             if (!InputManger.Instance.StartRun)
    16.             {
    17.                 InputManger.Instance.StartRun = true;
    18.             }
    19.             if (Input.mousePosition.y >= splitScreenY && Input.mousePosition.x <= splitScreenX)
    20.             {
    21.                 InputManger.Instance.Jump = true;
    22.             }
    23.             else if (Input.mousePosition.y < splitScreenY && Input.mousePosition.x <= splitScreenX)
    24.             {
    25.                 InputManger.Instance.Slide = true;
    26.                 StartCoroutine(TurnOff_Slide(0.2f));
    27.             }
    28.             else if (Input.mousePosition.x > splitScreenX)
    29.             {
    30.                 InputManger.Instance.Dash = true;
    31.             }
    32.         }
    33.     }
    34.     else
    35.     {
    36.         InputManger.Instance.Jump = false;
    37.         InputManger.Instance.Dash = false;
    38.         InputManger.Instance.Slide = false;
    39.     }
    40. }
    But now i am switching my game to a new input system since I have changed my plan to release this game just for my phone, now I also my to publish my game for Desktop. how can i do the same thing using a new input system?
     

    Attached Files: