- Home /
Why wont my script detect the input of my controller?
I am making a fps dependent on the xbox360 controller, when I was setting up the trigger to fire the gun I got this error Cannot implicitly convert type float' to
bool' , if it helps when I was setting up the input the only things I did was change the name to FireGun, changed the type to Joystick Axis and changed the Axis to 9th axis (Joysticks) here is the script:
using UnityEngine; using System.Collections;
public class Shoot_Script : MonoBehaviour {
public Rigidbody bulletPrefab;
public Transform barrelEnd;
void Start ()
{
}
void Update ()
{
if(Input.GetAxis("FireGun")
{
Instantiate (bulletPrefab, barrelEnd.position, barrelEnd.rotation);
}
}
}
Also yes, I did check and it's the input not the script itself. With a mouse it works fine
Answer by GAZEREAPER · Dec 24, 2015 at 04:37 PM
you forgot another ")" after the unput line.
And you cant just ask if a float is true or false, the input.getaxis asks the AXIS, wich usualy is something in between negative 1 or positive 1. If you want to check a button press, you have to use Input.GetButtonDown("FireGun") OR Input.GetButton("FireGun") if you want it to keep checking if it is held down all the time.
But if you really need to use axis you could use: public Rigidbody bulletPrefab; public Transform barrelEnd;
void Update ()
{
float fg = Input.GetAxis("FireGun");
if(fg < -0.01)
{
Instantiate (bulletPrefab, barrelEnd.position, barrelEnd.rotation);
}
}
However this will give the same effect as Input.GetButton, because it will keep executing everyframe as long as the button is pressed.
Good luck.
that was part of the problem but it still won't work I have a feeling that it's the way I set up the input manager here is a picture of it:
exactly what button are you trying to map? is it an axis or a button?
I'm trying to map the left trigger on a xbox360 controller