
🕹️ 실습 (2D 횡스크롤 스테이트머신)Enemy StateMachine// Idle과 MoveState가 SkeletonGroundedState을 상속받음public class SkeletonGroundedState : EnemyState{ protected Skeleton enemy; protected Transform player; public SkeletonGroundedState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName, Skeleton _enemy) : base(_enemyBase, _stateMachine, _animBoolName) { enemy = _en..

🕹️ 실습 (2D 횡스크롤 스테이트머신)Background Parallaxpublic class ParallaxBackground : MonoBehaviour{ private Camera cam; [SerializeField] private float parallaxEffect; private float xPosition; private float length; void Start() { cam = Camera.main; length = GetComponent().bounds.size.x; xPosition = transform.position.x; } void Update() { float distanc..

🕹️ 실습 (2D 횡스크롤 스테이트머신)벽 슬라이드, 벽 점프 구현public class PlayerWallSlideState : PlayerState{ public PlayerWallSlideState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName) { } public override void Enter() { base.Enter(); } public override void Update() { base.Update(); if (Input.GetKe..

드디어 StateMachine을 제대로 적용해봤다. 이해하고 적용하는데 시간이 좀 걸렸지만 코드가 훨씬 깔끔해졌고 확실히 유지보수에 용이할 것 같다!💻 UnityVelocityRigidbody.velocity는 물체의 현재 속도를 나타내는 벡터이 벡터는 방향 + 속도의 크기를 함께 가지고 있다예: (1, 0, 0)이면 x축 방향으로 1 단위 속도로 움직이는 중단위는 미터/초(m/s)Rigidbody rb = GetComponent();void Update(){ float move = Input.GetAxis("Horizontal"); rb.velocity = new Vector3(move * 5f, rb.velocity.y, 0f);}주의사항Rigidbody 필수velocity는 Rigidb..
💻 Unity2D RaycastisGrounded = Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDistance, whatIsGround);void OnDrawGizmos(){ Gizmos.DrawLine(groundCheck.position, new Vector3(groundCheck.position.x, groundCheck.position.y - groundCheckDistance));}groundCheck 위치에서 플레이어의 아래쪽(Vector2.down)으로 groundCheckDistance만큼 레이캐스트를 쏴서 땅이 있는지 확인isWallDetected = Physics2D.Raycast(wallCheck.pos..

💻 UnityBlend Tree (두 개 이상 애니메이션 합쳐서 사용)Friction(마찰력) 없애기Friction 0으로 한 후 Rigidbody에 넣어줌🕹️ 실습 (2D 횡스크롤 2)플레이어 대쉬 구현[Header("Dash Info")][SerializeField]private float dashSpeed;[SerializeField]private float dashDuration;// [SerializeField]private float dashTime;[SerializeField]private float dashCooldown;// [SerializeField]private float dashCooldownTimer;private void MovePlayer(){ xInput = Inp..
💻 Unity 디자인 패턴Strategy 패턴// Enemy.cspublic interface ImovementStrategy{ void Move(Transform transform, float speed);}public class StraightMovement: ImovementStrategy{ public void Move(Transform transform, float speed) { transform.Translate(Vector3.forward * speed * Time.deltaTime); }}public class ZigzagMovement : ImovementStrategy{ private float amplitude = 2f; private ..

💻 Unity 디자인 패턴Singletonpublic class GameManager : MonoBehaviour{ private static GameManager _instance; public static GameManager Instance { get { if (_instance == null) { _instance = FindFirstObjectByType(); if (_instance == null) { GameObject gameObject = new GameObject("GameManager"..