using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { public float speed; private Vector2 direction; void Update() { TakeInput(); Move(); } private void Move() { transform.Translate(direction * speed * Time.deltaTime); } private void TakeInput() { direction = Vector2.zero; if (TakeInput.GetKey(KeyCode.W)) { direction += Vector2.up; } if (TakeInput.GetKey(KeyCode.A)) { direction += Vector2.left; } if (TakeInput.GetKey(KeyCode.S)) { direction += Vector2.down; } if (TakeInput.GetKey(KeyCode.D)) { direction += Vector2.right; } } }
if (TakeInput.GetKey(KeyCode.W))
if (GetKey(KeyCode.W))
TakeInput
MonoBehavior::TakeInput
if (MonoBehavior::TakeInput(GetKey(KeyCode.W)) ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)