The triggers on xbox controller are axis, and when switching between mouse triggers and xbox, they do not behave the sameway, because the xbox triggers are basically Input.GetButton, which causes the firing of weapons to shoot repeatedly.
I tried Input.GetAxisRaw and nothing changed.
You can just use GetButtonDown with the name of an axis.
Answer by CodeMasterMike
Jan 08, 2013 at 10:16 AM
With the GetAxisRaw function you get either 0 or 1/-1 (depending on axis). So it does work like the GetButton function. If you want it to work as the GetButtonDown function, you need to add little more code.
private bool m_isAxisInUse = false;
if( Input.GetAxisRaw("Fire1") != 0)
if(m_isAxisInUse == false)
// Call your event function here.
m_isAxisInUse = true;
if( Input.GetAxisRaw("Fire1") == 0)
m_isAxisInUse = false;
In this very simple example, you see that the event function will be called once,
eventhough the axis-button keeps being pressed down. And when the axis-button is no longer pressed, the check gets restored, so that next input it will fire your event function again. I hope this example helps you.
how would this look in unityscript? and what do you put for axis in use? do you leave it as is, or do you really put the axis in use there? like m_9thAxis?
I don't know unityscript, but if you follow the thread of thought, Im sure you can rewrite it to unityscript, since its not a complicated code:
If your GetAxisRaw("Fire1") is pressed AND your "button is in use" is set to false, then set your "button is in use" boolean to true and do whatever you want to do when the button is pressed.
if your GetAxisRaw("Fire1") is NOT pressed, then set your "button is in use" boolean to false.
You can call the boolean variable whatever you want. If you have several buttons that you want handle like above, then you would need to rename them to something properly, yes.
Easiest to make and read would be something like:
There are always ways making the code more dynamic without having to hard code all variables, and so on. But that is more advanced topic.
Simple and useful answers always makes me happy. Thanks for this useful advice CodeMasterMike.
I am getting a "cannot implicitly convert type float to bool" error when implementing this. "fire 1" in my case is a bool. Do I just HAVE to recode some stuff and configure it to be a float since I am using an axis? I was using the Right Bumper on an xbox pad, but want the right trigger to do the job instead. GetButtonDown worked perfectly with the bumper. Advice real quick? :D
Re coding everything to be a float vs a bool worked perfectly. thanks!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
12 People are following this question.
Multiple Cars not working
Help converting C# to Unityscript
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much
GetButton delay not working properly?
how to use / simulate a using declaration in unityscript