public void Start() { if (instance != null) { Destroy(gameObject); return; } instance = this; DontDestroyOnLoad(gameObject); if (!IsCalibrated()) { SceneManager.LoadScene("Calibration"); } else { resting = PlayerPrefs.GetFloat("resting"); active = PlayerPrefs.GetFloat("active"); } int min; Microphone.GetDeviceCaps(null, out min, out max); audioClip = GetComponent <AudioSource>(); audioClip.clip = Microphone.Start(null, true, 10, max); audioClip.loop = true; while (Microphone.GetPosition(null) < 0) { ; } audioClip.Play(); }
// Update is called once per frame void Update() { int stage; for (stage = 0; stage < 4; stage++) { if (maxTimes[stage] - times[stage] > 0) { break; } } if (stage > 3) { EMGInput.Calibrate(rest / restN, hold / holdN); try { Destroy(FindObjectOfType <BirdNetworkManager>().gameObject); } catch { Debug.Log("No network manager to destroy found."); } SceneManager.LoadScene("Main Menu"); return; } times[stage] += Time.deltaTime; text.text = instructions[stage / 2]; if (stage % 2 == 0) { progressBar.UpdateProgress(1 - times[stage] / maxTimes[stage]); if (times[stage] - Time.deltaTime == 0) { progressBar.SetColor(readingColor); } } else { progressBar.UpdateProgress(times[stage] / maxTimes[stage]); if (times[stage] - Time.deltaTime == 0) { progressBar.SetColor(calibratingColor); } } switch (stage) { case 1: rest += EMGInput.GetIntensity(); restN++; break; case 3: hold += EMGInput.GetIntensity(); holdN++; break; } }
// Update is called once per frame void Update() { if (timer >= 0) { timer += Time.deltaTime; } text.text = "intensity: " + Mathf.Abs(EMGInput.GetIntensity()); if (latency != 0) { text.text += "\nlatency: " + latency + "s"; } }
// Update is called once per frame void Update() { progressBar.UpdateProgress(time / maxTime); if (recording) { time += Time.deltaTime; data.Add(EMGInput.GetIntensity()); if (time >= maxTime) { Save(); Toggle(); time = 0; data.Clear(); } } }
// Update is called once per frame void Update() { transform.rotation = Quaternion.AngleAxis(Mathf.Rad2Deg * Mathf.Atan(speed / 5), Vector3.forward); if (!isLocalPlayer) { return; } if (counter != 0) { counter--; } var pos = transform.position; if (alive && timer != 0) { Jump(); if (transform.position.y >= -0.5) { timer = 0; animator.SetBool("Dead", false); counter = invulnFrames; } } else if (alive) { #if UNITY_EDITOR || UNITY_EDITOR_64 if (Input.GetKey(KeyCode.UpArrow)) { pos.y += jumpSpeed * Time.deltaTime; } else if (Input.GetKey(KeyCode.DownArrow)) { pos.y -= jumpSpeed * Time.deltaTime; } #endif if (emg) { var target = EMGInput.GetRelativeIntensity() * 10f - 5f; var speed = (target - pos.y) / 0.1f; pos.y += speed * Time.deltaTime; } } else if (timer < disabledTime) { speed -= gravity * Time.deltaTime; timer += Time.deltaTime; } else { alive = true; speed = 0; } pos.y += speed * Time.deltaTime; if (pos.y > 5) { speed = 0; pos.y = 5; } pos.y = pos.y > -8 ? pos.y : -8; transform.position = pos; }
private void OnDestroy() { EMGInput.UnsubscribeFromSinglePulse(Jump); }