Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO.Ports;
- using System.Threading;
- public class SwitchAnimation : MonoBehaviour
- {
- public Animator ramsayAnimator;
- SerialPort serial = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
- // Update is called once per frame
- void FixedUpdate()
- {
- //int data = int.Parse(serial.ReadLine());
- try{
- if(serial == null){
- return;
- }
- if (!serial.IsOpen){
- serial.Open();
- }
- string data = serial.ReadLine();
- serial.ReadTimeout = 25;
- Debug.Log(data);
- if(data == "2"){
- ramsayAnimator.SetBool("bread", true);
- }else{
- ramsayAnimator.SetBool("bread", false);
- }
- Debug.LogWarning(data);
- }catch{
- Debug.LogWarning("Tried reading empty line.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement