ed1e24be1d
1. 회전 시 펜스가 사라지거나 남았던 현상 해결 - 펜스의 LOD가 여러개여서 필요한것만 남기고 삭제 2. 실드 ui 조정 - 별도의 스크립트와 핸들러를 이용해 빈 오브젝트(앵커)에 소속하게 변경 - pc에서는 화면 우측 상단으로 이동 - 모바일에서는 버튼 안으로 이동 3. 폰트 변경
91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
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<Rigidbody>();
|
|
|
|
// 초기 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<Animator>();
|
|
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<GameManager>()?.EndGame();
|
|
}
|
|
} |