- Home /
How can I control each door lock state individual and also to control all the doors lock states ?
The first script is attached to one empty GameObject :
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[ExecuteAlways]
public class DoorsLockManager : MonoBehaviour
{
public List<HoriDoorManager> Doors;
public List<bool> doorsLockState;
public HoriDoorManager horiDoorManager;
private void Start()
{
Doors = FindObjectsOfType<HoriDoorManager>().ToList();
doorsLockState = new bool[Doors.Count].ToList();
}
private void Update()
{
foreach(bool doorlockstate in doorsLockState)
{
horiDoorManager.doorLockState = doorlockstate;
}
}
The second script is attached to each door :
using UnityEngine;
using System.Collections;
public class HoriDoorManager : MonoBehaviour {
public DoorHori door1;
public DoorHori door2;
void OnTriggerEnter(){
if (door1!=null){
door1.OpenDoor();
}
if (door2!=null){
door2.OpenDoor();
}
}
}
What I want is in the first script the DoorsLockManager to make that if I toggle one of the flags in the bool list true/false it will lock/unlock the specific door the flag is belong to. belong to I mean maybe by indexs in the lists Doors and doorsLockState not sure how to do it.
and if it will work to add a global flag that will lock/unlock all the doors at once.
Your answer
![](https://koobas.hobune.stream/wayback/20220612232906im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help me with this code proplem,,Almost finish my game please help this once 3 Answers
Help. Newbie trying to have more than one button powered door a scene 1 Answer
Refresh panel with prefab contained value from json that created using array 0 Answers
setting a bool on another object's animator by player's raycast 2 Answers
Script sets same value to other script in all objects instead of just one. 1 Answer