I’ve been learning to use Unity/C# for a few months now (used to make games with Flash/AS3) so there is still a ton I have to learn.
In my current Unity game (Unity 5) I am using the First Person Controller. I understand enough of its code to manipulate it to make it behave the way I want but there are also other aspects of it that are beyond my current programming knowledge.
In the First Person Controller script there is this line:
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
As I am sure you guys know it checks if the Left Shift key is pressed and if not the character walks, otherwise the character runs.
I recently added gamepad support for my game and everything works great. Almost. I needed to modify the line above so that my character will run when the left trigger on the gamepad is pressed so I modified the line like so:
m_IsWalking = Input.GetAxis("Sprint") == 0;
I added a Sprint in the Input Manager for the left trigger on the gamepad. This works great as intended.
The issue I am trying to figure out with my current method is that I can only use one of the two lines I listed above. This means I’m currently forced either have the player sprint with the keyboard or with the controller. I can’t do both.
I initially tried:
m_IsWalking = !Input.GetKey(KeyCode.LeftShift) || Input.GetAxis("Sprint") == 0;
But that stupidly failed because I didn’t realize the First Person Controller variable m_IsWalking is a boolean when I first made this attempt.
Anyone here familiar enough with the code in the First Person Controller script that knows of a way to achieve what I want? I’m really hoping there is a simple solution I am missing that wouldn’t require me to mess with the script too much given there is a lot in there that just kind of goes over my head.