Advertisement
EmmyDev

Door & Bioscan

Dec 29th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5.  
  6. public class SecDoor : MonoBehaviour
  7. {
  8.     public string defName;
  9.     public bool scanning;
  10.  
  11.     public bool open = false;
  12.     public string macAdress;
  13.  
  14.     public Light lightIndicator;
  15.  
  16.     private float originalY;
  17.  
  18.     public TextMeshPro statusDisplay;
  19.  
  20.     private int percentage = 0;
  21.  
  22.     public TextMeshProUGUI taskText;
  23.     public GameObject player;
  24.     public GameObject bioScanArea;
  25.     [SerializeField] private GameObject lowerDoor;
  26.  
  27.     void Start()
  28.     {
  29.         originalY = transform.position.y;
  30.         defName = transform.name;
  31.         bioScanArea.SetActive(false);
  32.     }
  33.     void Update()
  34.     {
  35.         if(scanning == true)
  36.         {
  37.             lightIndicator.color = Color.yellow;
  38.             transform.tag = "ACTIVE_DOOR";
  39.             transform.name = macAdress;
  40.            
  41.         }
  42.         else
  43.         {
  44.            
  45.            
  46.             transform.tag = "INACTIVE_DOOR";
  47.             transform.name = defName;
  48.         }
  49.  
  50.         if(open)
  51.         {
  52.             taskText.text = "";
  53.             statusDisplay.text = "Bioscan complete";
  54.             lightIndicator.color = Color.green;
  55.             scanning = false;
  56.             if(transform.position.y < originalY + 5f)
  57.             {
  58.                 transform.Translate(Vector3.up * Time.deltaTime, Space.World);
  59.                 lowerDoor.transform.Translate(Vector3.down * Time.deltaTime, Space.World);
  60.             }
  61.            
  62.         }
  63.     }
  64.  
  65.     public void StartScan()
  66.     {
  67.         StartCoroutine(BIOSCAN());
  68.     }
  69.  
  70.     public IEnumerator BIOSCAN()
  71.     {
  72.         bioScanArea.SetActive(true);
  73.        
  74.         while(percentage < 35)
  75.         {
  76.             statusDisplay.text = "Bioscan in progress" + " \n <color=white> [" + percentage + "%] <color=white>";
  77.             yield return new WaitForSeconds(0.2f);
  78.             if(Vector3.Distance(bioScanArea.transform.position, player.transform.position) < 3f)
  79.             {
  80.                 percentage++;
  81.             }
  82.            
  83.         }
  84.         bioScanArea.SetActive(false);
  85.         statusDisplay.text = "Bioscan " + "ERROR <color=red>";
  86.         taskText.text = "Access door from terminal and OVERRIDE it";
  87.         scanning = true;
  88.         yield return null;
  89.     }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement