Advertisement
PedroArthurr

Interruptor - Unity

Feb 26th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. #region bibliotecas
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.IO.Ports;
  6. #endregion
  7.  
  8. public class Interruptor : MonoBehaviour
  9. {
  10.     #region Variaveis
  11.     string valor;
  12.     string mensages;
  13.     [SerializeField] GameObject luz;
  14.  
  15.     public SerialPort sp = new SerialPort("COM3", 9600);
  16.     #endregion
  17.  
  18.     #region Metodos Unity
  19.     void Awake()
  20.     {
  21.         sp.Open();
  22.     }
  23.     void Update()
  24.     {
  25.         valor = sp.ReadLine();
  26.         if(valor == "0")
  27.         {
  28.             Desativado();
  29.         }
  30.         if(valor == "1")
  31.         {
  32.             Ativado();
  33.         }
  34.     }
  35.     void OnApplicationQuit()
  36.     {
  37.         sp.Close();
  38.     }
  39.  
  40.     #endregion
  41.  
  42.     #region Metodos privados
  43.     void Ativado()
  44.     {
  45.         print("Ativado");
  46.         luz.SetActive(true);
  47.     }
  48.     void Desativado()
  49.     {
  50.         print("Desativado");
  51.         luz.SetActive(false);
  52.     }
  53.     #endregion
  54.  
  55.     #region Comentarios
  56.     /*
  57.       ■
  58.       ■
  59.       ■
  60.       ╔══════════════════════════════════════════════════════|>
  61.       ║               -
  62.       ║
  63.       ║   FB -> fb.com/NuKe.Pedro.Arthur
  64.       ║   IG -> @pedro.arthur.pa
  65.       ║  
  66.       ║
  67.       ╚══════════════════════════════════════════════════════|>
  68.       ■
  69.       ■
  70.       ■
  71.     */
  72.     #endregion
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement