
드디어 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"..

🕹️ 실습 (2D 횡스크롤)CinemachineCameraTracking Target을 Player로Add Extension을 Cinemachine Confiner 2D로Bounding Shape 2D를 Background로Lens 3.65BackgroundBox Collider 2D 추가isTrigger 체크PlayerDust// Playerpublic void ShowDust(GameObject dust){ Instantiate(dust, transform.position + new Vector3(-0.073f, -0.358f, 0), Quaternion.identity);}public float lifetime = 0.5f;private void Awake(){ Destroy(gameO..

💻 UnityLerp()Unity에서 보간(Interpolation) 을 수행하는 함수두 값 사이의 중간 값을 계산하는 기능을 하며, 주로 위치 이동, 색상 변화, 회전 보간 등에 사용된다Mathf.Lerp(a, b, t)숫자 보간Mathf.Lerp(0, 10, 0.5f) → 5Vector3.Lerp(a, b, t)위치 보간캐릭터 이동Color.Lerp(a, b, t)색상 보간UI 색상 변경QuaternionUnity에서 회전(Rotation) 을 표현하는 방식오일러 각(Euler angles) 대신 Quaternion 을 사용하여 회전을 다룬다Quaternion이 필요한 이유깜빡임 문제(Gimbal Lock) 방지오일러 각(Euler Angles)을 사용할 경우, 특정 각도에서 회전 축이 겹치는 문제..

🕹️ 실습 (Timeline)FadeIn, FadeOut 구현Timeline에 Screen Fador Track 추가 후 Image에 생성한 Image넣어줌이미지 크기 화면에 꽉 차게 확장시킴Add Screen Fador Clip 후 앞에껀 알파1로 뒤에껀 0으로 하고 합침애니메이션, 말풍선Samu 드래그로 추가후, 애니메이션도 드래그로 추가Knight 캐릭터도 Samu처럼 똑같이 추가해줌Canvas에 Text 추가후, Render 모드를 World Space로 변경, scale을 0.01, 0.01로 변경세번째 사진처럼 구조 만든 후 말풍선과 텍스트 설정Timeline에 Text Switcher Track 추가, Add Text Switch ClipCanvas Timeline에 드래그 하고 Add A..