Advertisement
GoodNoodle

DoorSetActive.cs

Mar 22nd, 2023 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DoorSetActive : MonoBehaviour
  6. {
  7.  
  8.     [SerializeField]
  9.     public GameObject[] switches;
  10.  
  11.     int numOfSwitches = 0;
  12.  
  13.  
  14.     private void Update()
  15.     {
  16.         GetNumOfSwitches();
  17.         GetSwitchDoor();
  18.     }
  19.     public int GetNumOfSwitches()
  20.     {
  21.         int num = 0;
  22.  
  23.         for (int i = 0; i <= switches.Length; i++)
  24.         {
  25.             numOfSwitches = num;
  26.  
  27.             if (switches[i].GetComponent<DoorSwitch>().isPressed == false)
  28.            
  29.                 num++;
  30.  
  31.              else if (switches[i].GetComponent<DoorSwitch>().isPressed == true)
  32.            
  33.                 numOfSwitches--;
  34.  
  35.             //return numOfSwitches;
  36.         }
  37.         return numOfSwitches;
  38.  
  39.     }
  40.  
  41.     public void GetSwitchDoor()
  42.     {
  43.         if (numOfSwitches <= 0)
  44.         {
  45.            Destroy(this.gameObject);
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement