using TMPro; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlayerController : MonoBehaviour { private Rigidbody playerRigidbody; public float speed = 8f; public int shieldCount = 3; private bool isShieldActive = false; public GameObject shieldVisual; public Image shieldIcon; public TextMeshProUGUI countText; // [추가] 조이스틱 연결용 변수 public VirtualJoystick joystick; public void Die() { gameObject.SetActive(false); GameManager gm = FindFirstObjectByType(); gm.EndGame(); } void Start() { playerRigidbody = GetComponent(); if (GameSettings.IsMobile) { if (shieldIcon != null) shieldIcon.gameObject.SetActive(false); if (countText != null) countText.gameObject.SetActive(false); } else { UpdateShieldUI(); } } void Update() { float x = 0; float 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"); } float xSpeed = x * speed; float zSpeed = z * speed; bool moveInput = (x != 0 || z != 0); Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed); playerRigidbody.linearVelocity = newVelocity; if (moveInput) { Vector3 moveDirection = new Vector3(x, 0f, z); Quaternion newRotation = Quaternion.LookRotation(moveDirection); transform.rotation = newRotation; } // PC일 때만 키보드 실드 입력 허용 if (!GameSettings.IsMobile && Input.GetKeyDown(KeyCode.Alpha1)) { ActivateShieldLogic(); } Animator anim = GetComponentInChildren(); if (anim != null) { anim.SetBool("isMoving", moveInput); } } public void ActivateShieldLogic() { if (shieldCount > 0 && !isShieldActive) { StartCoroutine(ActivateShield()); } } void UpdateShieldUI() { if (countText != null) { countText.text = shieldCount.ToString(); if (shieldCount <= 0) { countText.gameObject.SetActive(false); if (shieldIcon != null) { shieldIcon.color = new Color(0.2f, 0.2f, 0.2f, 0.5f); } } } } IEnumerator ActivateShield() { isShieldActive = true; shieldCount--; UpdateShieldUI(); if (shieldVisual != null) shieldVisual.SetActive(true); yield return new WaitForSeconds(2f); if (shieldVisual != null) shieldVisual.SetActive(false); isShieldActive = false; } }