Hello. I have been looking around for hours, but I can’t find what I am looking for, so now I seek help.
I want to be able to change pace on my character by using the keybindings “1, 2, 3 and 4”, and only have to press the buttons once to change pace(with other words I don’t want to have to hold the button down until I want a new pace, just one touch).
Stop: 1
Walk: 2
Trot: 3
Sprint: 4
^ that is what I had in mind.
I want to control where the character is heading with the arrow keys, but control the pace with 1, 2, 3 and 4.
Every tip is appreciated: tutorials, examples, etc…
Based on what you wrote i’d guess your looking for something like this:
int speed = 1;
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown("1"))
{
speed = 1;
}
if(Input.GetKeyDown("2"))
{
speed = 2;
}
if(Input.GetKeyDown("w")) //sorry dont remember the arrow key bindings
{
transform.Translate(Vector3.forward);
}
//Alternativly you may want 2 butons one to increase speed as long as the button is held down
//and one to decrease speed as long as it is held down
if(Input.GetKey("1"))
{
//Increases speed by 1 every second.
speed += Time.deltaTime;
}
if(Input.GetKeyDown("2"))
{
speed -= Time.deltaTime;
}
}