[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
+17 -2
View File
@@ -13,10 +13,13 @@ public class GameManager : MonoBehaviour
private float surviveTime;
private bool isGameover;
public GameObject restartButton;
public void EndGame()
{
isGameover = true;
gameoverText.SetActive(true);
restartButton.SetActive(true);
float bestTime = PlayerPrefs.GetFloat("BestTime");
if(surviveTime > bestTime)
@@ -26,6 +29,7 @@ public class GameManager : MonoBehaviour
}
recordText.text = "Best Time: " + (int)bestTime;
}
@@ -46,9 +50,15 @@ public class GameManager : MonoBehaviour
}
else
{
if(Input.GetKeyDown(KeyCode.R))
// 1. PC: R키
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("Game");
RestartGame();
}
// 2. 모바일/PC: 클릭 또는 터치 (화면 아무데나 눌러도 재시작)
if (Input.GetMouseButtonDown(0))
{
RestartGame();
}
}
@@ -58,4 +68,9 @@ public class GameManager : MonoBehaviour
{
return surviveTime;
}
public void RestartGame()
{
UnityEngine.SceneManagement.SceneManager.LoadScene(1);
}
}
+13
View File
@@ -0,0 +1,13 @@
using UnityEngine;
public class GameSettings : MonoBehaviour
{
public static bool IsMobile;
void Awake()
{
IsMobile = Application.isMobilePlatform;
DontDestroyOnLoad(gameObject);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 75598ca86eac5ec46a9dcc7713ac9b25
+1 -1
View File
@@ -22,7 +22,7 @@ public class NewMonoBehaviourScript : MonoBehaviour
float currentTime = gameManager.GetSurviveTime();
int targetStep = 1;
if (currentTime > 10f) targetStep = 4;
if (currentTime > 30f) targetStep = 4;
else if (currentTime > 20f) targetStep = 3;
else if (currentTime > 10f) targetStep = 2;
else targetStep = 1;
+17
View File
@@ -0,0 +1,17 @@
using UnityEngine;
public class PlatformUIHandler : MonoBehaviour
{
public GameObject joystickUI; // 모바일 조이스틱 오브젝트
public GameObject buttonUI; // 가상 버튼 오브젝트
void Start()
{
// 아까 Intro에서 저장한 값을 확인
bool isMobile = GameSettings.IsMobile;
// 모바일이면 켜고, 아니면 끔
if (joystickUI != null) joystickUI.SetActive(isMobile);
if (buttonUI != null) buttonUI.SetActive(isMobile);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: feb0dc7f5acf8d04d9aa26416992cb24
+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;
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using UnityEngine;
using TMPro;
public class RestartTextHandler : MonoBehaviour
{
// [SerializeField]를 쓰면 private이어도 인스펙터 창에 뜹니다!
[SerializeField] private TextMeshProUGUI restartText;
void OnEnable()
{
// 이제 null 체크를 할 필요도 거의 없습니다. (인스펙터에서 넣을 거니까요)
if (restartText == null)
{
Debug.LogError("인스펙터에 텍스트 오브젝트를 할당해주세요!");
return;
}
if (GameSettings.IsMobile)
restartText.text = "Touch the screen to restart";
else
restartText.text = "Press the R key to restart";
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b82599e72e3c0b040a9e796f3f6e6d6a