Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 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.  
  7. public class SwitchAnimation : MonoBehaviour
  8. {
  9. public Animator ramsayAnimator;
  10.  
  11. SerialPort serial = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
  12.  
  13. // Update is called once per frame
  14. void FixedUpdate()
  15. {
  16.  
  17.  
  18. //int data = int.Parse(serial.ReadLine());
  19.  
  20.  
  21. try{
  22.  
  23. if(serial == null){
  24. return;
  25. }
  26.  
  27. if (!serial.IsOpen){
  28. serial.Open();
  29. }
  30.  
  31. string data = serial.ReadLine();
  32. serial.ReadTimeout = 25;
  33. Debug.Log(data);
  34.  
  35. if(data == "2"){
  36. ramsayAnimator.SetBool("bread", true);
  37. }else{
  38. ramsayAnimator.SetBool("bread", false);
  39. }
  40. Debug.LogWarning(data);
  41.  
  42. }catch{
  43. Debug.LogWarning("Tried reading empty line.");
  44. }
  45.  
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement