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