0

After looking up various tutorials and guides and not fixing my solution, I would like to know how to set up the left stick on an Xbox 360 controller so that it controls my character. I have tried setting up my Horizontal and Vertical axes in the InputManager, but despite this, whenever I run my game, the character just stands still, and the joystick does not work. I know the controller works after testing the ABXY buttons. Any help would be appreciated. Thanks!

Note: In the InputManager, I have the type set to Joystick Axis, the axis set to the corresponding directions (horizontal, x-axis : vertical, y-axis), and the joy num set to "Get Motion from all Joysticks".

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class testScript : MonoBehaviour {

public GameObject circle;
public float range;

// Use this for initialization
void Start () {
    circle = GameObject.Find ("Circle");
}

// Update is called once per frame
void Update () {
    float translation = Time.deltaTime * 10;
    bool xbox_a = Input.GetButton ("XboxA");
    bool xbox_b = Input.GetButton ("XboxB");
    bool xbox_x = Input.GetButton ("XboxX");
    bool xbox_y = Input.GetButton ("XboxY");
    float Hvalue = Input.GetAxis ("Horizontal");
    float Vvalue = Input.GetAxis ("Vertical");

    float xPos = Hvalue * range;
    float yPos = Vvalue * range;

    circle.transform.Translate(xPos, yPos, 0);

    /*if (Input.GetKey ("w")) {
        circle.transform.position += Vector3.up * translation;
    } if (Input.GetKey ("a")) {
        circle.transform.position += Vector3.left * translation;
    } if (Input.GetKey ("s")) {
        circle.transform.position += Vector3.down * translation;
    } if (Input.GetKey ("d")) {
        circle.transform.position += Vector3.right * translation;
    }*/
    if (Input.GetKey ("e") || xbox_y) {
        circle.GetComponent<Renderer>().material.color = Color.yellow;
    }
    if (Input.GetKey ("r") || xbox_x) {
        circle.GetComponent<Renderer>().material.color = Color.blue;
    }
    if (Input.GetKey ("f") || xbox_b) {
        circle.GetComponent<Renderer>().material.color = Color.red;
    }
    if (Input.GetKey ("c") || xbox_a) {
        circle.GetComponent<Renderer>().material.color = Color.green;
    }

}
}
rjkiv
  • 23
  • 6
  • Seems as though you haven't assigned a value to "range". If the game is running without errors i can only assume that the range variable would = 0 and thus Hvalue or Vvalue * range would always = 0? Unless you have assigned it to anything other than 0 in the inspector. – Sam Jan 13 '17 at 16:31
  • I tried setting the value of "range" to 10, 50, etc. different numbers, but the result is still the same unfortunately. – rjkiv Jan 13 '17 at 19:48

0 Answers0