diff --git a/Assets/Scripts/Mechanics/AnimationController.cs b/Assets/Scripts/Mechanics/AnimationController.cs index ed58455..0efaaaf 100644 --- a/Assets/Scripts/Mechanics/AnimationController.cs +++ b/Assets/Scripts/Mechanics/AnimationController.cs @@ -39,7 +39,7 @@ namespace Platformer.Mechanics SpriteRenderer spriteRenderer; Animator animator; - PlatformerModel model = Simulation.GetModel(); + PlatformerModel model; protected virtual void Awake() { @@ -48,13 +48,17 @@ namespace Platformer.Mechanics if (spriteRenderer == null) spriteRenderer = GetComponentInChildren(); animator = GetComponent(); if (animator == null) animator = GetComponentInChildren(); + // BT12-Dev 2026-05-12 — field initializer Awake 영역 이동 (Editor·Play mode 전환 시 model 미초기화 NRE 회피). + try { model = Simulation.GetModel(); } catch { model = null; } } protected override void ComputeVelocity() { + float jumpMod = model != null ? model.jumpModifier : 1f; + float jumpDec = model != null ? model.jumpDeceleration : 0.5f; if (jump && IsGrounded) { - velocity.y = jumpTakeOffSpeed * model.jumpModifier; + velocity.y = jumpTakeOffSpeed * jumpMod; jump = false; } else if (stopJump) @@ -62,18 +66,22 @@ namespace Platformer.Mechanics stopJump = false; if (velocity.y > 0) { - velocity.y = velocity.y * model.jumpDeceleration; + velocity.y = velocity.y * jumpDec; } } // PD 명시 2026-05-08 — PlayerController와 동일 영역 정합: 좌측 향한 sprite 기준 우측 이동 시 flipX=true - if (move.x > 0.01f) - spriteRenderer.flipX = true; - else if (move.x < -0.01f) - spriteRenderer.flipX = false; + if (spriteRenderer != null) + { + if (move.x > 0.01f) spriteRenderer.flipX = true; + else if (move.x < -0.01f) spriteRenderer.flipX = false; + } - animator.SetBool("grounded", IsGrounded); - animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed); + if (animator != null) + { + animator.SetBool("grounded", IsGrounded); + animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed); + } targetVelocity = move * maxSpeed; }