Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Touch movement/transform positioning help

Discussion in 'Scripting' started by Simon89Turner, Jun 7, 2020.

  1. Simon89Turner

    Simon89Turner

    Joined:
    May 28, 2020
    Posts:
    4
    Hi Guys,

    I am trying to create a script related to touch for android phones.

    What i am trying to achieve is to be able to make a touch input that if i slide my finger from top to bottom the screen acts as a type of slider which changes the transform position of a player object so for example a player object could be set to 10 on the y axis and sliding finger on the screen down would drop the ten to 9 then 8 then 7 etc.

    I would then like to be able to do the opposite so sliding from bottom to top would increase the y axis of the object so from 0 to 1 to 2 and so on.

    It is essentially making the screen into a slider that links to the transform positioning.

    Not sure the best approach to this would be at all, any help would be greatly appreciated.

    Kind Regards,

    Simon.
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You can record the position of the first touch and then while the screen is still being touch, monitor how far it has moved and move your object based on that.
     
  3. Simon89Turner

    Simon89Turner

    Joined:
    May 28, 2020
    Posts:
    4
    Hi WarmedxMints thank you for your response to this, i think i understand what you mean, would you be able to give me q c code script example of this at all? I'm quite new to this so may take me a while to work out, thanks.
     
  4. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    783
    Hi,

    Have you tried to search for Unity swipe control tutorial?
    This for example might be a start for the swipe, and direction detection:
     
  5. sStarS

    sStarS

    Joined:
    Mar 27, 2020
    Posts:
    19
    I actually tried this tutorial the other day for a camera , it didn't go that well..only moved left and right and only by a bit, only after I deleted the script a thought came to me to increase the swipe area, I guess i'll write it again and see how it goes so thank you I didn't remember the name I searched a lot of stuff so couldn't find it a second time