using System.Collections; using System.Collections.Generic; using UnityEngine; public class Moving : MonoBehaviour { public float speed = 5f; [SerializeField] private Rigidbody rb; [SerializeField] private float jumpForce = 5f; void Start() { } // Update is called once per frame void Update() { Vector3 direction = Vector3.zero; if (Input.GetKey(KeyCode.W)) direction += Vector3.forward; if (Input.GetKey(KeyCode.S)) direction += Vector3.back; if (Input.GetKey(KeyCode.A)) direction += Vector3.left; if (Input.GetKey(KeyCode.D)) direction += Vector3.right; if (Input.GetKeyDown(KeyCode.Space)) rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); if (Input.GetKey(KeyCode.LeftControl)) Debug.Log("left ctrl active"); direction = direction.normalized; transform.position += direction * (speed * Time.deltaTime); } }