72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BlueWaterProject;
|
|
using UnityEngine;
|
|
|
|
public class Restaurant : MonoBehaviour
|
|
{
|
|
public Transform restaurantSwitch;
|
|
private bool isSwitchOn = false;
|
|
public Transform mainDoor;
|
|
public Transform[] guestNpc;
|
|
public GameObject[] mainLight;
|
|
|
|
public GameObject npcPrefab;
|
|
|
|
public void RestaurantSwitchOnOff()
|
|
{
|
|
isSwitchOn = !isSwitchOn;
|
|
|
|
if (isSwitchOn)
|
|
{
|
|
restaurantSwitch.rotation *= Quaternion.Euler(0, 0, -90);
|
|
foreach (var light in mainLight)
|
|
{
|
|
light.SetActive(true);
|
|
}
|
|
|
|
var door = mainDoor.GetComponent<WW_Door>();
|
|
door._animator.SetBool("Open", true);
|
|
|
|
StartCoroutine(ActivateNPCs());
|
|
}
|
|
else
|
|
{
|
|
restaurantSwitch.rotation *= Quaternion.Euler(0, 0, 90);
|
|
foreach (var light in mainLight)
|
|
{
|
|
light.SetActive(false);
|
|
}
|
|
|
|
var door = mainDoor.GetComponent<WW_Door>();
|
|
door._animator.SetBool("Open", false);
|
|
|
|
StopAllCoroutines();
|
|
}
|
|
}
|
|
|
|
IEnumerator ActivateNPCs()
|
|
{
|
|
foreach (var npcData in DataManager.Inst.NpcDataSo.npcDataList)
|
|
{
|
|
if (!isSwitchOn) // 스위치가 꺼지면 코루틴을 즉시 종료
|
|
yield break;
|
|
|
|
var waitTime = UnityEngine.Random.Range(3, 11); // 3초에서 10초 사이의 랜덤 대기 시간
|
|
yield return new WaitForSeconds(waitTime); // 랜덤 대기
|
|
|
|
if (!isSwitchOn) // 대기 후 스위치 상태 다시 확인
|
|
yield break;
|
|
|
|
// NPC 인스턴스화 및 데이터로 초기화
|
|
var npcInstance = Instantiate(npcPrefab, transform.position, Quaternion.identity, transform); // 원하는 위치와 회전 값으로 수정하세요
|
|
var tycoonNpc = npcInstance.GetComponent<TycoonNpc>();
|
|
|
|
if (tycoonNpc != null)
|
|
{
|
|
tycoonNpc.npcData = npcData;
|
|
}
|
|
}
|
|
}
|
|
} |