Files
VRProject/Assets/_Scripts/BossWebSpawner.cs
ohgushiyuga 52341100ed otamesi
2026-08-27 12:51:15 +09:00

81 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossWebSpawner : MonoBehaviour, IPauseable
{
[SerializeField] private GameObject warningMarkerPrefab;
[SerializeField] private GameObject webPrefab;
[field: SerializeField] public float WebAvoidanceRadius { get; private set; } = 2.5f;
public List<Vector3> ActiveWebPositions { get; private set; } = new List<Vector3>();
private bool isPaused;
private void Start()
{
if (WorldPauseManager.Instance != null)
{
WorldPauseManager.Instance.Register(this);
}
}
private void OnDestroy()
{
if (WorldPauseManager.Instance != null)
{
WorldPauseManager.Instance.Unregister(this);
}
}
public void Pause() => isPaused = true;
public void Resume() => isPaused = false;
private IEnumerator WaitForUnpausedSeconds(float duration)
{
float timer = 0f;
while (timer < duration)
{
if (!isPaused)
{
timer += Time.deltaTime;
}
yield return null;
}
}
public void SpawnWarningAndWeb(Vector3 targetGroundPos, float delay, float webDuration)
{
StartCoroutine(SpawnWebRoutine(targetGroundPos, delay, webDuration));
}
private IEnumerator SpawnWebRoutine(Vector3 pos, float delay, float duration)
{
ActiveWebPositions.Add(pos);
GameObject marker = null;
if (warningMarkerPrefab != null)
{
marker = Instantiate(warningMarkerPrefab, pos + new Vector3(0, 0.5f, 0), Quaternion.identity);
}
yield return WaitForUnpausedSeconds(delay);
if (marker != null) Destroy(marker);
if (webPrefab != null)
{
Quaternion webRotation = Quaternion.Euler(270f, 0f, 0f);
GameObject web = Instantiate(webPrefab, pos + new Vector3(0, 0.5f, 0), webRotation);
yield return WaitForUnpausedSeconds(duration);
if (web != null) Destroy(web);
}
else
{
yield return WaitForUnpausedSeconds(duration);
}
ActiveWebPositions.Remove(pos);
}
}