As the title says, I want to script to make a key get pressed all the time.
For example if I want to get the player to go to the right all the time, I’d like to get the right arrow key pressed all the time, how can I do this?
As the title says, I want to script to make a key get pressed all the time.
For example if I want to get the player to go to the right all the time, I’d like to get the right arrow key pressed all the time, how can I do this?
Something like this should work, you don’t need to continually have the right arrow pressed to have the character constantly moving right. Uncomment the moveDir inputs below if you want WASD style movement.
using UnityEngine;
using System.Collections;
public class Character : MonoBehaviour {
public int speed = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
characterMovement();
}
void characterMovement()
{
//put your player movement code here
Vector3 moveDir = Vector3.right;
// moveDir.x = Input.GetAxis("Horizontal"); // get result of AD keys in X
//moveDir.z = Input.GetAxis("Vertical"); // get result of WS keys in Z
// move this object at frame rate independent speed:
transform.position += moveDir * speed * Time.deltaTime;
}
}