Files
jongjae0305 8298b2559c [Update] 게임형식 및 오류수정
1. 게임형태 변경
  - Game스텝에서 기존 1단계, 2단계 수정(회전만 가능하게).
  - ShootButton을 만들어 플레이어도 총알을 쏠수 있도록 수정.
  - Bullet, BulletSpawner, PlayerController를 수정
  - SpawnZone을 생성하여 기존 고정이던 스포너를 랜덤으로 생성.

2. 오류 수정
 - 모바일 버전 시 플레이어가 한방향만 보던 형상 수정.
 - 펜스에서 플레이어 캐릭터가 닿으면 회전하던 형상 수정.
2026-04-29 09:22:08 +09:00

79 lines
1.7 KiB
C#

using UnityEngine;
public class BulletSpawner : MonoBehaviour
{
public GameObject prefab;
public float bulletSpeed = 8f;
Transform target;
public Transform firePoint;
public float min = 0.5f;
public float max = 3f;
float rate;
float time;
void Start()
{
time = 0f;
rate = Random.Range(min, max);
PlayerController player = FindFirstObjectByType<PlayerController>();
if (player != null)
{
target = player.transform;
}
else
{
Debug.LogError("BulletSpawner: 플레이어를 찾을 수 없습니다! 씬에 PlayerController가 있는지 확인하세요.");
}
if (GameManager.instance != null)
{
GameManager.instance.RegisterSpawner(this);
}
}
void Update()
{
if (target == null) return;
time += Time.deltaTime;
transform.LookAt(target);
if (time >= rate)
{
time = 0f;
rate = Random.Range(min, max);
GameObject obj = Instantiate(prefab, firePoint.transform.position, firePoint.transform.rotation);
obj.transform.LookAt(target);
Bullet bulletScript = obj.GetComponent<Bullet>();
if (bulletScript != null)
{
bulletScript.speed = bulletSpeed;
bulletScript.isPlayerBullet = false;
}
}
}
void OnDestroy()
{
if (GameManager.instance != null)
{
GameManager.instance.UnregisterSpawner(this);
if (!GameManager.instance.isGameover)
{
GameManager.instance.RequestRespawn();
}
}
}
}