HrDisplay.cs 601 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using TMPro;
  3. using UnityEngine;
  4. public class HrDisplay : MonoBehaviour{
  5. public int hrSensorId;
  6. public TextMeshProUGUI heartRateDisplay;
  7. private HrReceiver hrReceiver;
  8. private bool heartRateDisplayAvailable;
  9. private void Start()
  10. {
  11. hrReceiver = new HrReceiver(hrSensorId);
  12. hrReceiver.StartScan();
  13. heartRateDisplayAvailable = heartRateDisplay != null;
  14. }
  15. private void Update()
  16. {
  17. if (heartRateDisplayAvailable)
  18. {
  19. heartRateDisplay.text = $"{(hrReceiver?.HeartRate ?? 0):0} bpm";
  20. }
  21. }
  22. }