UnityGame/Assets/Scripts/DoorController.cs

45 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-10-27 10:53:47 +03:00
using UnityEngine;
using System.Collections.Generic;
public class DoorController : MonoBehaviour
{
public List<GameObject> doors; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float dayDuration = 120f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dayDuration <20> DayNightCycle
private int currentDoorIndex = -1;
private float currentTime = 0f;
void Start()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (GameObject door in doors)
{
door.SetActive(true);
}
}
void Update()
{
currentTime += Time.deltaTime;
if (currentTime >= dayDuration)
{
OpenNextDoor();
currentTime = 0f;
}
}
void OpenNextDoor()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
if (currentDoorIndex != -1)
{
doors[currentDoorIndex].SetActive(true);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
currentDoorIndex = (currentDoorIndex + 1) % doors.Count;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
doors[currentDoorIndex].SetActive(false);
}
}