using UnityEngine; public class Movement2D : MonoBehaviour { [SerializeField] private float moveSpeed = 0.0f; [SerializeField] private Vector3 moveDirection = Vector3.zero; [SerializeField] private float addSpeed = 0.0f; private float baseMoveSpeed; [SerializeField] private float dashSpeed = 0.0f; // moveSpeed 변수의 프로퍼티(Property) (Get 가능) public float MoveSpeed { set => moveSpeed = Mathf.Max(0, value); get => moveSpeed; } private void Awake() { baseMoveSpeed = moveSpeed; } private void Update() { moveSpeed += addSpeed; transform.position += moveDirection * moveSpeed * Time.deltaTime; } private void Start() { InvokeRepeating("Dash", 2.0f, 1.0f); InvokeRepeating("ResetMoveSpeed", 2.5f, 1.0f); } private void Dash() { moveSpeed += dashSpeed; } public void MoveTo(Vector3 direction) { moveDirection = direction; } public void ResetMoveSpeed() { moveSpeed = baseMoveSpeed; } } /* * File : Movement2D.cs * Desc * : 이동이 가능한 모든 오브젝트에게 부착 * * Functions * : MoveTo() - 외부에서 호출해 이동 방향을 설정 * */