2024-03-03 10:55:46 +00:00
|
|
|
using System;
|
2024-02-11 05:21:29 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Restaurant : MonoBehaviour
|
|
|
|
{
|
2024-03-03 10:55:46 +00:00
|
|
|
public Transform restaurantSwitch;
|
|
|
|
private bool isSwitchOn = false;
|
2024-03-03 14:04:28 +00:00
|
|
|
public Transform mainDoor;
|
|
|
|
public Transform[] guestNpc;
|
|
|
|
public GameObject[] mainLight;
|
2024-02-11 05:21:29 +00:00
|
|
|
|
2024-03-03 10:55:46 +00:00
|
|
|
public void RestaurantSwitchOnOff()
|
2024-02-11 05:21:29 +00:00
|
|
|
{
|
2024-03-10 10:11:50 +00:00
|
|
|
isSwitchOn = !isSwitchOn;
|
|
|
|
|
|
|
|
if (isSwitchOn)
|
2024-03-03 10:55:46 +00:00
|
|
|
{
|
|
|
|
restaurantSwitch.rotation *= Quaternion.Euler(0, 0, -90);
|
2024-03-03 14:04:28 +00:00
|
|
|
foreach (var light in mainLight)
|
|
|
|
{
|
|
|
|
light.SetActive(true);
|
|
|
|
}
|
2024-03-10 08:51:09 +00:00
|
|
|
|
|
|
|
var door = mainDoor.GetComponent<WW_Door>();
|
|
|
|
door._animator.SetBool("Open", true);
|
2024-03-10 10:11:50 +00:00
|
|
|
|
|
|
|
StartCoroutine(ActivateNPCs());
|
2024-03-03 10:55:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
restaurantSwitch.rotation *= Quaternion.Euler(0, 0, 90);
|
2024-03-03 14:04:28 +00:00
|
|
|
foreach (var light in mainLight)
|
|
|
|
{
|
|
|
|
light.SetActive(false);
|
|
|
|
}
|
2024-03-10 10:11:50 +00:00
|
|
|
|
2024-03-10 08:51:09 +00:00
|
|
|
var door = mainDoor.GetComponent<WW_Door>();
|
|
|
|
door._animator.SetBool("Open", false);
|
2024-03-10 10:11:50 +00:00
|
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator ActivateNPCs()
|
|
|
|
{
|
|
|
|
foreach (var npc in guestNpc)
|
|
|
|
{
|
|
|
|
if (!isSwitchOn) // 스위치가 꺼지면 코루틴을 즉시 종료
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
if (!npc.gameObject.activeInHierarchy) // NPC가 비활성화 상태인 경우만
|
|
|
|
{
|
|
|
|
var waitTime = UnityEngine.Random.Range(3, 11); // 1초에서 10초 사이의 랜덤 대기 시간
|
|
|
|
yield return new WaitForSeconds(waitTime); // 랜덤 대기
|
|
|
|
|
|
|
|
if (!isSwitchOn) // 대기 후 스위치 상태 다시 확인
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
npc.gameObject.SetActive(true); // NPC 활성화
|
|
|
|
}
|
2024-03-03 10:55:46 +00:00
|
|
|
}
|
2024-02-11 05:21:29 +00:00
|
|
|
}
|
2024-03-03 10:55:46 +00:00
|
|
|
}
|