[Update] 휴대폰 조이스틱 연결 및 스크립트 변경

1. 휴대폰에서 실시가능하도록 조이스틱 및 버튼 입력
2. 콜라이더 및 트리거 구조 변경
3. 로테이션 단계이상함 감지 - 수정 예정
This commit is contained in:
jongjae0305
2026-04-21 17:45:51 +09:00
parent 15bb71750b
commit 6c84f865d8
209 changed files with 8639 additions and 2654 deletions
+58 -39
View File
@@ -2,41 +2,61 @@ using TMPro;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //코드로 ui를 건들기 위해서 임포트
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 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();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
playerRigidbody = GetComponent<Rigidbody>();
UpdateShieldUI(); //함수발동
if (GameSettings.IsMobile)
{
if (shieldIcon != null) shieldIcon.gameObject.SetActive(false);
if (countText != null) countText.gameObject.SetActive(false);
}
else
{
UpdateShieldUI();
}
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
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;
@@ -44,21 +64,19 @@ public class PlayerController : MonoBehaviour
bool moveInput = (x != 0 || z != 0);
Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
playerRigidbody.linearVelocity = newVelocity;
if(moveInput)
if (moveInput)
{
Vector3 moveDirection = new Vector3(x, 0f, z);
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
transform.rotation = newRotation;
}
if (Input.GetKeyDown(KeyCode.Alpha1) && shieldCount > 0 && !isShieldActive) //1숫자가 눌리고 카운트가 1이상이고 실드가 활동한 상태이면
// PC일 때만 키보드 실드 입력 허용
if (!GameSettings.IsMobile && Input.GetKeyDown(KeyCode.Alpha1))
{
StartCoroutine(ActivateShield()); //비동기적으로 함수를 발동하라
ActivateShieldLogic();
}
Animator anim = GetComponentInChildren<Animator>();
@@ -68,16 +86,22 @@ public class PlayerController : MonoBehaviour
}
}
public void ActivateShieldLogic()
{
if (shieldCount > 0 && !isShieldActive)
{
StartCoroutine(ActivateShield());
}
}
void UpdateShieldUI()
{
if (countText != null) //텍스트가 비어있지 않다면
if (countText != null)
{
countText.text = shieldCount.ToString(); //실드의 카운트를 문자열로 저장
countText.text = shieldCount.ToString();
if (shieldCount <= 0)
{
countText.gameObject.SetActive(false); //0이하면 활동에 페일즈를 저장
countText.gameObject.SetActive(false);
if (shieldIcon != null)
{
shieldIcon.color = new Color(0.2f, 0.2f, 0.2f, 0.5f);
@@ -86,20 +110,15 @@ public class PlayerController : MonoBehaviour
}
}
IEnumerator ActivateShield() //코루틴
IEnumerator ActivateShield()
{
isShieldActive = true; //실드는 트루로 변경
shieldCount--; //실드 카운트는 감소
isShieldActive = true;
shieldCount--;
UpdateShieldUI();
UpdateShieldUI(); //업데이트
if (shieldVisual != null) shieldVisual.SetActive(true); //만약에 실드비주얼이 비어있지 않다면 트루를 저장
yield return new WaitForSeconds(2f); // 2초동안만
if (shieldVisual != null) shieldVisual.SetActive(false); //만약에 실드비주얼이 비어있지 않다면면 페일즈
isShieldActive = false; //실드 페일즈
if (shieldVisual != null) shieldVisual.SetActive(true);
yield return new WaitForSeconds(2f);
if (shieldVisual != null) shieldVisual.SetActive(false);
isShieldActive = false;
}
}
}