[Update] 로직 변경 및 회전 문제 해결 등
1. 회전 시 펜스가 사라지거나 남았던 현상 해결 - 펜스의 LOD가 여러개여서 필요한것만 남기고 삭제 2. 실드 ui 조정 - 별도의 스크립트와 핸들러를 이용해 빈 오브젝트(앵커)에 소속하게 변경 - pc에서는 화면 우측 상단으로 이동 - 모바일에서는 버튼 안으로 이동 3. 폰트 변경
This commit is contained in:
@@ -47,16 +47,17 @@ public class NewMonoBehaviourScript : MonoBehaviour
|
||||
currentStep = step;
|
||||
switch (step)
|
||||
{
|
||||
case 1 :
|
||||
case 1:
|
||||
SetSpawnersActive(2);
|
||||
if (rotator != null) rotator.enabled = false;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
case 2:
|
||||
SetSpawnersActive(4);
|
||||
if (rotator != null) rotator.enabled = false;
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
case 3:
|
||||
SetSpawnersActive(4);
|
||||
if (rotator != null) rotator.enabled = true;
|
||||
break;
|
||||
|
||||
@@ -1,56 +1,46 @@
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
private Rigidbody playerRigidbody;
|
||||
[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 Image shieldIcon;
|
||||
public TextMeshProUGUI countText;
|
||||
|
||||
// [추가] 조이스틱 연결용 변수
|
||||
public VirtualJoystick joystick;
|
||||
|
||||
public void Die()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
GameManager gm = FindFirstObjectByType<GameManager>();
|
||||
gm.EndGame();
|
||||
}
|
||||
public ShieldUIHandler shieldUI; // UI 전용 스크립트 참조
|
||||
|
||||
void Start()
|
||||
{
|
||||
playerRigidbody = GetComponent<Rigidbody>();
|
||||
|
||||
if (GameSettings.IsMobile)
|
||||
{
|
||||
if (shieldIcon != null) shieldIcon.gameObject.SetActive(false);
|
||||
if (countText != null) countText.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateShieldUI();
|
||||
}
|
||||
// 초기 UI 상태 반영
|
||||
if (shieldUI != null) shieldUI.UpdateShieldUI(shieldCount);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float x = 0;
|
||||
float z = 0;
|
||||
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;
|
||||
x = input.x; z = input.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -58,67 +48,44 @@ public class PlayerController : MonoBehaviour
|
||||
z = Input.GetAxis("Vertical");
|
||||
}
|
||||
|
||||
float xSpeed = x * speed;
|
||||
float zSpeed = z * speed;
|
||||
playerRigidbody.linearVelocity = new Vector3(x * speed, 0f, z * speed);
|
||||
|
||||
bool moveInput = (x != 0 || z != 0);
|
||||
|
||||
Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
|
||||
playerRigidbody.linearVelocity = newVelocity;
|
||||
|
||||
if (moveInput)
|
||||
if (x != 0 || z != 0)
|
||||
{
|
||||
Vector3 moveDirection = new Vector3(x, 0f, z);
|
||||
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
|
||||
transform.rotation = newRotation;
|
||||
}
|
||||
|
||||
// PC일 때만 키보드 실드 입력 허용
|
||||
if (!GameSettings.IsMobile && Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
ActivateShieldLogic();
|
||||
transform.rotation = Quaternion.LookRotation(new Vector3(x, 0f, z));
|
||||
}
|
||||
|
||||
// 애니메이션
|
||||
Animator anim = GetComponentInChildren<Animator>();
|
||||
if (anim != null)
|
||||
{
|
||||
anim.SetBool("isMoving", moveInput);
|
||||
}
|
||||
if (anim != null) anim.SetBool("isMoving", (x != 0 || z != 0));
|
||||
}
|
||||
|
||||
public void ActivateShieldLogic()
|
||||
{
|
||||
if (shieldCount > 0 && !isShieldActive)
|
||||
{
|
||||
StartCoroutine(ActivateShield());
|
||||
StartCoroutine(ActivateShieldRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
private IEnumerator ActivateShieldRoutine()
|
||||
{
|
||||
isShieldActive = true;
|
||||
shieldCount--;
|
||||
UpdateShieldUI();
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,6 @@ public class RestartTextHandler : MonoBehaviour
|
||||
if (GameSettings.IsMobile)
|
||||
restartText.text = "Touch the screen to restart";
|
||||
else
|
||||
restartText.text = "Press the R key to restart";
|
||||
restartText.text = "Press the 'R' key to restart";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ShieldRelocator : MonoBehaviour
|
||||
{
|
||||
public Transform pcAnchor; // PC 화면 위치
|
||||
public Transform mobileAnchor; // 모바일 버튼 내부 위치
|
||||
|
||||
void Awake()
|
||||
{
|
||||
bool isMobile = Application.isMobilePlatform;
|
||||
Transform targetParent = isMobile ? mobileAnchor : pcAnchor;
|
||||
|
||||
transform.SetParent(targetParent, false);
|
||||
|
||||
RectTransform rect = GetComponent<RectTransform>();
|
||||
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a581d3c527475634d98e2afd54a74f85
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class ShieldUIHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image shieldIcon;
|
||||
[SerializeField] private TextMeshProUGUI countText;
|
||||
|
||||
// UI 업데이트만 담당하는 함수
|
||||
public void UpdateShieldUI(int count)
|
||||
{
|
||||
if (countText != null)
|
||||
{
|
||||
countText.text = count.ToString();
|
||||
// 개수가 0이면 텍스트 숨기기
|
||||
countText.gameObject.SetActive(count > 0);
|
||||
}
|
||||
|
||||
if (shieldIcon != null)
|
||||
{
|
||||
// 색상 조절 로직
|
||||
shieldIcon.color = (count > 0) ? Color.white : new Color(0.2f, 0.2f, 0.2f, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b245920762fd34b488c890ebe44abdd5
|
||||
Reference in New Issue
Block a user