- Home /
The question is answered, right answer was accepted
Can't get Triggers to Work [Solved]
public class PlayerControl : MonoBehaviour {
public float moveSpeed;
private Rigidbody2D rb;
private Vector2 moveInput;
private Vector2 moveVelocity;
public ControlGun shot;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput * moveSpeed;
}
void FixedUpdate()
{
rb.velocity = moveVelocity;
if (Input.GetButtonDown("Shot")) {
shot.isFiring = true;
}
if (Input.GetButtonUp("Shot"))
{
shot.isFiring = false;
}
}
}
I've managed to get it working for other inputs, such as keys, mouse button, and controller buttons, but I can't get the axis controls working. From what I've found, I'm supposed to switch the "GetButtonUp" and "GetButtonDown" to "GetAxis" (I have went into the InputManager already, creating a new axis with Type set to "Joystick Axis", Axis set to "9th axis (Joysticks)" and Joy Num to "Joystick 1" (Although I've tried "Get Motion from all Joysticks", "Joystick 3" and "Joystick 9". Whenever I try to replace "GetButtonUp" or "GetButtonDown" with "GetAxis", it gives me an error saying "Cannot implicitly convert type 'float' to 'bool' ". (The axis name is Shot) I'm on Windows, I'm trying to use the left trigger and I'm using an Xbox 360 controller.
Answer by Windchilled · Dec 04, 2017 at 08:48 PM
I got it to work by writing "Input.GetAxis("Shot") == 1", for GetButtonDown and "Input.GetAxis("Shot") == 0", for GetButtonUp.