UnityGame/Assets/Scripts/DoorController.cs
2024-10-27 10:53:47 +03:00

45 lines
1.0 KiB
C#

using UnityEngine;
using System.Collections.Generic;
public class DoorController : MonoBehaviour
{
public List<GameObject> doors; // Ñïèñîê äâåðåé
public float dayDuration = 120f; // Äîëæåí ñîîòâåòñòâîâàòü dayDuration â DayNightCycle
private int currentDoorIndex = -1;
private float currentTime = 0f;
void Start()
{
// Çàêðûòü âñå äâåðè â íà÷àëå
foreach (GameObject door in doors)
{
door.SetActive(true);
}
}
void Update()
{
currentTime += Time.deltaTime;
if (currentTime >= dayDuration)
{
OpenNextDoor();
currentTime = 0f;
}
}
void OpenNextDoor()
{
// Çàêðûòü ïðåäûäóùóþ äâåðü
if (currentDoorIndex != -1)
{
doors[currentDoorIndex].SetActive(true);
}
// Ïåðåéòè ê ñëåäóþùåé äâåðè
currentDoorIndex = (currentDoorIndex + 1) % doors.Count;
// Îòêðûòü òåêóùóþ äâåðü
doors[currentDoorIndex].SetActive(false);
}
}