OldBlueWater/BlueWater/Assets/02.Scripts/Tycoon/Restaurant.cs

72 lines
2.1 KiB
C#
Raw Normal View History

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;
2024-04-15 16:03:56 +00:00
using BlueWaterProject;
2024-02-11 05:21:29 +00:00
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-04-15 16:03:56 +00:00
public GameObject npcPrefab;
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);
}
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
var door = mainDoor.GetComponent<WW_Door>();
door._animator.SetBool("Open", false);
2024-03-10 10:11:50 +00:00
StopAllCoroutines();
}
}
IEnumerator ActivateNPCs()
{
2024-05-02 07:36:39 +00:00
foreach (var npcData in DataManager.Inst.NpcDataSo.npcDataList)
2024-03-10 10:11:50 +00:00
{
if (!isSwitchOn) // 스위치가 꺼지면 코루틴을 즉시 종료
yield break;
2024-04-15 16:03:56 +00:00
var waitTime = UnityEngine.Random.Range(3, 11); // 3초에서 10초 사이의 랜덤 대기 시간
yield return new WaitForSeconds(waitTime); // 랜덤 대기
if (!isSwitchOn) // 대기 후 스위치 상태 다시 확인
yield break;
2024-03-10 10:11:50 +00:00
2024-04-15 16:03:56 +00:00
// NPC 인스턴스화 및 데이터로 초기화
var npcInstance = Instantiate(npcPrefab, transform.position, Quaternion.identity, transform); // 원하는 위치와 회전 값으로 수정하세요
var tycoonNpc = npcInstance.GetComponent<TycoonNpc>();
2024-03-10 10:11:50 +00:00
2024-04-15 16:03:56 +00:00
if (tycoonNpc != null)
{
2024-04-22 17:52:54 +00:00
tycoonNpc.npcData = npcData;
2024-03-10 10:11:50 +00:00
}
2024-03-03 10:55:46 +00:00
}
2024-02-11 05:21:29 +00:00
}
2024-03-03 10:55:46 +00:00
}