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;
}
}
}