I want to make it so that after the user inputs WAS or D, the player stops moving after the input. So, if the user inputted W to go upward, they’ll move 1 unit before stopping, instead of how it is now, where if they hold down input the player will just keep going. Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveblocking1 : MonoBehaviour {
Vector3 pos;
public float speed = 100f;
// Use this for initialization
void Start () {
pos = transform.position;
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKey(KeyCode.A) && transform.position == pos) {
pos += new Vector3(-1, 0, 0);
}
if(Input.GetKey(KeyCode.D) && transform.position == pos) {
pos += new Vector3 (1, 0, 0);
}
if(Input.GetKey(KeyCode.W) && transform.position == pos) {
pos += new Vector3 (0, 1, 0);
}
if(Input.GetKey(KeyCode.S) && transform.position == pos) {
pos += new Vector3(0,-1, 0);
}
transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}
}