using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { [Header("Movement")] public float speed = 8f; private Rigidbody playerRigidbody; public VirtualJoystick joystick; [Header("Shield System")] public int shieldCount = 3; private bool isShieldActive = false; public GameObject shieldVisual; public ShieldUIHandler shieldUI; // UI 전용 스크립트 참조 void Start() { playerRigidbody = GetComponent(); // 초기 UI 상태 반영 if (shieldUI != null) shieldUI.UpdateShieldUI(shieldCount); } void Update() { HandleMovement(); // PC 입력 처리 (모바일 아닐 때만) if (!GameSettings.IsMobile && Input.GetKeyDown(KeyCode.Alpha1)) { ActivateShieldLogic(); } } void HandleMovement() { float x = 0, z = 0; if (GameSettings.IsMobile && joystick != null) { Vector2 input = joystick.GetInput(); x = input.x; z = input.y; } else { x = Input.GetAxis("Horizontal"); z = Input.GetAxis("Vertical"); } playerRigidbody.linearVelocity = new Vector3(x * speed, 0f, z * speed); if (x != 0 || z != 0) { transform.rotation = Quaternion.LookRotation(new Vector3(x, 0f, z)); } // 애니메이션 Animator anim = GetComponentInChildren(); if (anim != null) anim.SetBool("isMoving", (x != 0 || z != 0)); } public void ActivateShieldLogic() { if (shieldCount > 0 && !isShieldActive) { StartCoroutine(ActivateShieldRoutine()); } } private IEnumerator ActivateShieldRoutine() { isShieldActive = true; shieldCount--; // UI 업데이트 위임 if (shieldUI != null) shieldUI.UpdateShieldUI(shieldCount); if (shieldVisual != null) shieldVisual.SetActive(true); yield return new WaitForSeconds(2f); if (shieldVisual != null) shieldVisual.SetActive(false); isShieldActive = false; } public void Die() { gameObject.SetActive(false); FindFirstObjectByType()?.EndGame(); } }