- Home /
'Getbutton' Or 'GetAxis' Not working at all!
I started making a fantasy game, and when it came to melee, I used the code (in Js) 'if ( Input.GetAxis("Fire1")) Which I know should work perfectly, But my Axis buttons dont work at all! Then I tried to Make an fps, (c#) and when i typed in the code 'Input.GetAxis("Vertical"); It doesnt work at All! I dont know whats happened to my axis buttons but I cant make ANY game because they dont work/respond, i've also researched all the right settings too in project settings > Input.
Unitys's pointless until my axis buttons Work!
Try Input.GetButton("Fire1")
not Input.GetAxis("Fire1")
.
I didnt mean it like that, I meant that Anything I put 'Fire1' 'Vertical' 'horizontal' It never works, but the scripts fine. Its as if the actual inputs just dont work
Have you checked the input? It says you researched them, have you tried doing something like:
var vertical : float;
var horizontal : float;
function Update () {
vertical = Input.GetAxis("Vertical");
horizontal = Input.GetAxis("Horizontal");
}
That's how I use my axis keys.
This question is rather difficult to debug without any further information, but a few tips you could try.
I presume you are using
$$anonymous$$onobehaviour
methods such asvoid Start()
,void Awake()
or evenvoid Update()
. If so, have you made sure your script is attached to a GameObject on the scene?Try using
Debug.Log("Something")
before and after your I`nput.GetAxis("Vertical");` to see if the code is actually being executed.
I'm also having an issue where I'm not getting any values for GetAxis("Vertical"); or likewise for horizontal
Answer by Sanchay · Dec 26, 2014 at 10:50 PM
Try this
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement);
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Convert C# Into UnityScript - Events in Unityscript 2 Answers
Unity v4.6 Joystick? 2 Answers
Application.ExternalCall Issue 0 Answers