GetAxis help?
So I don't know which this would of been under : Forums or Answers
But I am more familiar with how Answers work in regards to selecting the best, and forums I don't know where I would put this
So I don't fully understand GetAxis, is it just the settings like the Sensitivity and all that?
Or is it like something like I put it in a code like :
if (Input.GetAxis("Horizontal"))
{
//code here
}
do have a mild form of autism sorry If I sound dumb.
Answer by HenryStrattonFW · Feb 04, 2017 at 04:42 PM
GetAxis() returns a value based on the settings for that axis in the InputManager. Most common use for this is for things like "Horizontal" and "Vertical" to obtain movement input from arrow/wasd keys or joysticks.
It will return a floating point number in the range -1 to 1 indicating the type of input. For example, if you took this script and attached it to an object, pressing the arrow keys or wasd keys will cause the object to move around.
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private float m_Speed;
void Update()
{
Vector3 lMove = Vector3.zero;
lMove.x = Input.GetAxis("Horizontal");
lMove.y = Input.GetAxis("Vertical");
transform.Translate(lMove * Time.deltaTime * m_Speed);
}
}
So It's like a movement type of thing that if identified (in your script, as l$$anonymous$$ove.x and l$$anonymous$$ove.y)
It can be used like a x & y movement ?
(in your script, as
transform.Translate(l$$anonymous$$ove * Time.deltaTime * m_Speed); `
)
It can be used for anything you might want to use a number for, a common use is like my exmaple, using it for movement. However you could just as easily take the values from GetAxis() and use them to change the volume of some audio, trigger an event if above/below a specific threshold, all sorts.
So say I used Vertical and got like "W" (I think that's how it goes)
Depended on how long I hold "W", That will increase the value of the float?
You're welcome, good luck with your project!