Search Unity

Xbox controller buttons not working ?

Discussion in 'Scripting' started by Quast, Aug 24, 2016.

  1. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    I'm trying to use xbox controller in my game. the left and right analogues running but buttons not working. here is my code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MOVEMENT : MonoBehaviour
    5. {
    6.     private Rigidbody rb;
    7.  
    8.     void Start()
    9.     {
    10.               rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         if (Input.GetKey(KeyCode.J))  {
    16.                 rb.AddForce(Vector2.up * 20);
    17.             }
    18.  
    19.         if( Input.GetButton("Xbox-X"))  {
    20.                 rb.AddForce(Vector2.up * 20);
    21.                 Debug.Log("xbox X");
    22.            }
    23.  
    24.     }
    25.     }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Thank you for you reply.
    OK. now it's work except D-pad ? I don't know way. It's button.
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    dpad is dependent on your target platform... are you going for mac (it's a button)? windows (it's an axis)? type needs to be set appropriately :)
     
    Quast likes this.
  5. TheOnly1ZombieGamer

    TheOnly1ZombieGamer

    Joined:
    Dec 20, 2017
    Posts:
    1
    for me on dpad even if i set it on the axis it still doesnt read it, same for my right trigger i set on Fire 1, and both of them should be being read.