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

How to I get the Input Code/Axis for the Xbox Controller Left/Right Bumper?

Discussion in 'Scripting' started by Hotpots, May 3, 2016.

  1. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    At the moment I am perfectly able to get button codes for the keyboard and xbox buttons however I have no idea what the codes are to access whether the xbox bumper button is pressed?

    At the moment I have:

    Code (CSharp):
    1.         if (other.gameObject.tag == "Tricycle" && !trInteracted && Input.GetKey ("joystick button 2"))
    2.         {
    3.             //Do Stuff!
    So this works with the xbox "B" button but how would I get this to work with the L/R bumper?

    Thanks in advance! :)
     
  2. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
  3. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    have you checked that on Project Settings > Input controls that you have set it to 3rd axis?
     
  4. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    At the moment I have:



    Code (CSharp):
    1.         else if (Input.GetAxis("3rd Axis"))
    2.         {
    3.             Debug.Log ("HELLOOOOOO!");
    4.         }
    I get this error obviously:


    It seems that getting triggers working seems to be much more challenging than the xbox buttons :(
     
    Scopeles likes this.
  5. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Code (CSharp):
    1. Input.GetAxis("Right Trigger")
    You have to get the Name, not the axis :p
     
  6. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    I have this:

    Code (CSharp):
    1.         else if (Input.GetAxis("Right Trigger"))
    2.         {
    3.             Debug.Log ("HELLOOOOOO!");
    4.         }
    And I still get the same error :(
     
  7. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Sorry forgot to mention, as it's in an if statement, you have to check it against a condition , completely forgot :p
    Code (CSharp):
    1. else if (Input.GetAxis("Right Trigger") > 0)
     
    Hotpots likes this.
  8. Hotpots

    Hotpots

    Joined:
    Apr 9, 2015
    Posts:
    143
    Ahhh, I really appreciate your help Rob, but for some reason my Debug.Log is not working thus I guess the if statement is not detecting my trigger press. As when I change the condition to >= 0 it outputs the message.

    If I can't get the triggers working I may just resort to buttons. :(


    EDIT: I got it working, changed the input manager from joystick 1 to get motion from all joysticks.

    Thanks Rob!
     
    Last edited: May 3, 2016
  9. Scopeles

    Scopeles

    Joined:
    Jan 28, 2021
    Posts:
    1
    thank you soo much this actually worked for me