Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System.IO.Ports;
  4.  
  5. public class ReadUSBChangeShader : MonoBehaviour {
  6.  
  7. private Renderer holoRenderer;
  8.  
  9. SerialPort sp; //whatever COM arduino uses
  10.  
  11. private void Awake(){
  12. try{
  13. sp = new SerialPort("COM3", 9600);
  14. }
  15. catch(System.Exception ){
  16.  
  17. }
  18. }
  19. void Start(){
  20. try{
  21. sp.Open();
  22. sp.ReadTimeout = 1;
  23. }
  24. catch(System.Exception){
  25.  
  26. }
  27. }
  28.  
  29. void Update () {
  30. if (sp.IsOpen)
  31. {
  32. try{
  33. sp.ReadByte(); // DO WHATEVER THE *YOU WANT
  34. }
  35. catch (System.Exception){
  36.  
  37. }
  38. }
  39. else{
  40. if(Input.GetKeyDown(KeyCode.R)){
  41. //Do something
  42. Debug.Log("lee alterno");
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement