Guest User

Untitled

a guest
Jul 23rd, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO.Ports;
  5. using System.Threading;
  6. using UnityEngine.UI;
  7.  
  8.  
  9. public class LEDSONOFF : MonoBehaviour
  10. {
  11.   public Animator anim;
  12.   private SerialPort serial = new SerialPort("COM3",9600);
  13.   public GameObject QUESTIONS;
  14.  void Start()
  15.  {
  16.  anim.SetBool("butclose", false);
  17.  serial.Open();  
  18.  
  19.  QUESTIONS.gameObject.SetActive (false);
  20.    
  21.  }
  22.  
  23.  void Update()
  24.  {
  25.  readdata();
  26.  
  27.   //Debug.Log(serial.ReadByte());
  28.  }
  29.  
  30.   void startANIM()
  31.    {  
  32.      if (anim.GetBool("butclose") == false)
  33.      {
  34.         anim.SetBool("butclose", true);
  35.      }
  36.  
  37.     }
  38.      
  39.  
  40.  void readdata()
  41.  {
  42.    
  43.     if (serial.ReadByte() == 8)
  44.        
  45.          { startANIM();
  46.          QUESTIONS.gameObject.SetActive (false);
  47.           Debug.Log("konpka");}
  48.  
  49.    if (serial.ReadByte() == 9)
  50.      { Debug.Log("DEVYAT");
  51.      
  52.     }
  53.      if (serial.ReadByte() ==5)
  54.    
  55.        { Debug.Log("pYAT");}
  56.  
  57.      
  58.  }
  59.        
  60.  
  61.  void OnMouseDown()
  62.     {
  63.        anim.SetBool("butclose", false);
  64.        anim.SetTrigger("click1can");
  65.            
  66.          QUESTIONS.gameObject.SetActive (true);
  67.  
  68.        if (serial.IsOpen == true)
  69.         {
  70.            
  71.         serial.Write("A");
  72.        
  73.         Debug.Log("SEND A");
  74.         }
  75.         if (serial.IsOpen == false)
  76.         {
  77.            
  78.         serial.Open();
  79.         serial.Write("A");
  80.         }
  81.     }
  82. }
Add Comment
Please, Sign In to add comment