Search Unity

Question Input problem on Android Phone after BUILD

Discussion in 'Scripting' started by WENKO, Sep 26, 2022.

  1. WENKO

    WENKO

    Joined:
    Apr 27, 2019
    Posts:
    39

    The script moved only the left and right arrows on the keyboard, and the Platform was changed to Android when building.

    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.RightArrow)) { GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, 0); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, 0); }
    After creating the .apk file and running it on a Androidphone, it was possible to tilt the phone left and right instead of controlling it with a finger.

    Is there a way to set this at build time to change this to a left and right finger movement?, Please.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Oh my goodness, don't write code like that.

    If you have more than one or two dots (.) in a single statement, you're just being mean to yourself.

    How to break down hairy lines of code:

    http://plbm.com/?p=248

    Break it up, practice social distancing in your code, one thing per line please.

    "Programming is hard enough without making it harder for ourselves." - angrypenguin on Unity3D forums

    "Combining a bunch of stuff into one line always feels satisfying, but it's always a PITA to debug." - StarManta on the Unity3D forums

    Are you asking how to do finger input? There's like ten billion tutorials on Youtube.

    Are you asking how conditional compilation works? That's pretty well covered too, but it will look something like:

    Code (csharp):
    1. #if UNITY_ANDROID || UNITY_IPHONE
    2.    // do touch input
    3. #else
    4.    // do non-touch input
    5. #endif
    If you want simple finger input that just works regardless of mouse or finger, I have a bunch of stuff in my proximity buttons package.

    proximity_buttons is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/proximity_buttons

    https://github.com/kurtdekker/proximity_buttons

    https://gitlab.com/kurtdekker/proximity_buttons

    https://sourceforge.net/projects/proximity-buttons/