[Update] 게임형식 및 오류수정
1. 게임형태 변경 - Game스텝에서 기존 1단계, 2단계 수정(회전만 가능하게). - ShootButton을 만들어 플레이어도 총알을 쏠수 있도록 수정. - Bullet, BulletSpawner, PlayerController를 수정 - SpawnZone을 생성하여 기존 고정이던 스포너를 랜덤으로 생성. 2. 오류 수정 - 모바일 버전 시 플레이어가 한방향만 보던 형상 수정. - 펜스에서 플레이어 캐릭터가 닿으면 회전하던 형상 수정.
This commit is contained in:
+107
-20
@@ -1,4 +1,6 @@
|
||||
using NUnit.Framework.Constraints;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
@@ -11,36 +13,41 @@ public class GameManager : MonoBehaviour
|
||||
public Text recordText;
|
||||
|
||||
private float surviveTime;
|
||||
private bool isGameover;
|
||||
public bool isGameover;
|
||||
|
||||
public GameObject restartButton;
|
||||
|
||||
public void EndGame()
|
||||
public static GameManager instance;
|
||||
|
||||
public AudioSource leadAudio;
|
||||
public AudioSource deathAudio;
|
||||
|
||||
public List<BulletSpawner> activeSpawners = new List<BulletSpawner>();
|
||||
public Transform player;
|
||||
public SpawnZone spawnZone;
|
||||
public GameObject spawnerPrefab;
|
||||
|
||||
public void RegisterSpawner(BulletSpawner s) => activeSpawners.Add(s);
|
||||
public void UnregisterSpawner(BulletSpawner s) => activeSpawners.Remove(s);
|
||||
|
||||
public int maxSpawnerCount = 2;
|
||||
|
||||
public Transform rotationPlate;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
isGameover = true;
|
||||
gameoverText.SetActive(true);
|
||||
restartButton.SetActive(true);
|
||||
|
||||
float bestTime = PlayerPrefs.GetFloat("BestTime");
|
||||
if(surviveTime > bestTime)
|
||||
{
|
||||
bestTime = surviveTime;
|
||||
PlayerPrefs.SetFloat("BestTime", bestTime);
|
||||
}
|
||||
|
||||
recordText.text = "Best Time: " + (int)bestTime;
|
||||
|
||||
if (instance == null) instance = this;
|
||||
}
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
surviveTime = 0;
|
||||
isGameover = false;
|
||||
|
||||
if (leadAudio != null) leadAudio.Play();
|
||||
if (deathAudio != null) deathAudio.Stop();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(!isGameover)
|
||||
@@ -50,12 +57,10 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1. PC: R키
|
||||
if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
RestartGame();
|
||||
}
|
||||
// 2. 모바일/PC: 클릭 또는 터치 (화면 아무데나 눌러도 재시작)
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
RestartGame();
|
||||
@@ -73,4 +78,86 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
public void PlayDeathMusic()
|
||||
{
|
||||
if (leadAudio != null) leadAudio.Stop();
|
||||
if (deathAudio != null) deathAudio.Play();
|
||||
}
|
||||
|
||||
public void EndGame()
|
||||
{
|
||||
isGameover = true;
|
||||
gameoverText.SetActive(true);
|
||||
restartButton.SetActive(true);
|
||||
|
||||
float bestTime = PlayerPrefs.GetFloat("BestTime");
|
||||
if (surviveTime > bestTime)
|
||||
{
|
||||
bestTime = surviveTime;
|
||||
PlayerPrefs.SetFloat("BestTime", bestTime);
|
||||
}
|
||||
|
||||
recordText.text = "Best Time: " + (int)bestTime;
|
||||
|
||||
}
|
||||
|
||||
public Vector3 GetValidSpawnPosition()
|
||||
{
|
||||
int maxAttempts = 10;
|
||||
for (int i = 0; i < maxAttempts; i++)
|
||||
{
|
||||
Vector3 candidate = spawnZone.GetRandomPosition();
|
||||
|
||||
|
||||
if (Vector3.Distance(candidate, player.position) < 5f) continue;
|
||||
|
||||
bool isOverlap = false;
|
||||
foreach (var spawner in activeSpawners)
|
||||
{
|
||||
if (Vector3.Distance(candidate, spawner.transform.position) < 3f)
|
||||
{
|
||||
isOverlap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOverlap) return candidate;
|
||||
}
|
||||
return spawnZone.GetRandomPosition();
|
||||
}
|
||||
|
||||
public void RequestRespawn()
|
||||
{
|
||||
StartCoroutine(RespawnRoutine());
|
||||
}
|
||||
|
||||
IEnumerator RespawnRoutine()
|
||||
{
|
||||
yield return new WaitForSeconds(3f);
|
||||
|
||||
Vector3 validPos = GetValidSpawnPosition();
|
||||
|
||||
GameObject newSpawner = Instantiate(spawnerPrefab, validPos, Quaternion.identity);
|
||||
|
||||
if (rotationPlate != null)
|
||||
{
|
||||
newSpawner.transform.SetParent(rotationPlate);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMaxSpawnerCount(int newCount)
|
||||
{
|
||||
maxSpawnerCount = newCount;
|
||||
|
||||
int currentCount = activeSpawners.Count;
|
||||
if (currentCount < maxSpawnerCount)
|
||||
{
|
||||
int needed = maxSpawnerCount - currentCount;
|
||||
for (int i = 0; i < needed; i++)
|
||||
{
|
||||
RequestRespawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user