Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android Input , Unity

Discussion in 'Editor & General Support' started by HelloFinland, Sep 27, 2014.

  1. HelloFinland

    HelloFinland

    Joined:
    Jun 14, 2014
    Posts:
    5
    Hello,
    I have completed my game and i did build setting for android and now i can run my game in my mobile while testing it. I am getting little confused about the movements of the player in my game. I am using horizontal and vertical input for running and walking for my player and when i made build setting , i dont know how to make run or walk the player in android as there is no keyboard like that in my phone. Any suggestion would be very great.
    Thank you :)
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The Input class offers methods for mobile devices, such as GetTouch etc.
     
  3. Pasixi

    Pasixi

    Joined:
    Nov 9, 2013
    Posts:
    6
    You can also try Input.mousePosition. It works on computer and touch screens, too!
    For example:
    float relativeXPos = Input.mousePosition.x / Screen.width;
    float relativeYPos = Input.mousePosition.y / Screen.height;
    // returns zero if no touch
     
    Last edited: Sep 27, 2014
  4. HelloFinland

    HelloFinland

    Joined:
    Jun 14, 2014
    Posts:
    5
    Okay, but how do i make walk for my third person. In webplayer, it has horizontal and vertical axis. How do i input those vertical and horizontal axis in android ? :)
     
  5. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You need to calculate it based on the touch position.
     
  6. HelloFinland

    HelloFinland

    Joined:
    Jun 14, 2014
    Posts:
    5
    i know those things, i just wanted to ask , how do i use that horizontal and vertical axis movement in android input. How do i declare those things in touch input :)
     
  7. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You have to work with these phases if you do not use the method mentioned by @Pasixi.
    In every frame you can determine the phase of a specific touch, based on that you can do calculations with the touch's position. E.g. difference in x direction would be right/left, in y direction up/down, or both... depends on your needs.