using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { private float h; private float v; private float r; [SerializeField] private float moveSpeed = 5.0f; [SerializeField] private float turnSpeed = 200.0f; [SerializeField] private Animator animator; void Start() { // 컴포넌트 추출 및 할당 animator = this.gameObject.GetComponent(); } void Update() { Move(); PlayerAnimation(); } private void PlayerAnimation() { animator.SetFloat("Forward", v); animator.SetFloat("Strafe", h); } private void Move() { h = Input.GetAxis("Horizontal"); // 1차원 연속값 -1.0 ~ 0.0 ~ +1.0 v = Input.GetAxis("Vertical"); // -1.0f ~ 0.0f ~ +1.0f r = Input.GetAxis("Mouse X"); // 마우스의 X축 이동 변위값(Delta Value) // 이동 로직 // 벡터의 덧셈연산 => 벡터의 정규화 (Vector Normalized) Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h); transform.Translate(moveDir.normalized * Time.deltaTime * moveSpeed); // 회전 로직 transform.Rotate(Vector3.up * r * turnSpeed * Time.deltaTime); } } /* Vector3.forward = Vector3(0, 0, 1) Vector3.up = Vector3(0, 1, 0) Vector3.right = Vector3(1, 0, 0) Vector3.one = Vector3(1, 1, 1) Vector3.zero = Vector3(0, 0, 0) */ /* 벡터의 덧셈연산 */