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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Access Axes by button

Discussion in 'Scripting' started by DasJonny, Oct 20, 2018.

  1. DasJonny

    DasJonny

    Joined:
    May 15, 2017
    Posts:
    31
    Hey there!

    I want to access my Horizontal Axis by buttons (so one button sets the axis to -1 the other to +1).

    How to i access the axis by script?

    I know that i can get the current state of the axis by "Input.GetAxis("Horizontal")" but how to i SET the axis?
     
  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,459
    You need to explain what you mean exactly by "setting the axis", what you are trying to do.
     
  3. Shadoninja

    Shadoninja

    Joined:
    Nov 12, 2013
    Posts:
    26
    I will jump in and give you an example. I have a game that is similar to Pokemon/Zelda ALttP. Sometimes, the player triggers a new scene to load and this causes the axis values to be hard reset (let's not even go down the path of why that is or is not a good thing).

    In my case, I want to give the player the option to continue holding down an axis and continue their movement. Currently, the player is required to let go of their dpad/arrow key, then repress it to keep moving in that direction. That is pretty clunky-feeling. If we could access the axes by the corresponding button (not the axis value), we could break out of the very awkward limitations put in place by the axis system.
     
  4. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,459
    Ah now I understand!

    I have no idea how to do that but I'm glad I can learn about that as well, as soon as someone has answered your question. :)

    Generally speaking though, players stop pressing the "onward" key when a new scene is loading... I do that.
     
  5. DasJonny

    DasJonny

    Joined:
    May 15, 2017
    Posts:
    31
    Yeah, thats the same problem, in another scene

    In my case I have a player with a movement script that moves by GetAxisRaw("Horizontal")*movementspeed * time.deltaTime
    Currently it is made for PC but i thought about porting it to mobile.

    I know the usual way to do the mobile movement, but i thought about just putting 2 buttons, one for setting the axis to +, one to - One to keep the difference between mobile and pc port quite low (and only left and right movement is required).

    I googled a little around and found out that there is actually no way to say "Horizontal Axis = Value" by script