// Update is called once per frame void Update() { if (audioSource.isPlaying && audioSource.time >= (audioRunningTime - 0.5)) // minus 0.5 to 59.5, to prevent audio finishing before { audioSource.Stop(); audioFinishedPlaying = true; shouldDisableBtns = 0; if (pictureModeWasOnSoSwitchBack) { videoToggle.isOn = false; pictureToggle.isOn = true; pictureModeWasOnSoSwitchBack = false; } } else //if (audioSource.isPlaying) { audioFinishedPlaying = false; } //When the user hits the spacebar, pause/play, but not while adding images and only works while playing if (Input.GetKeyDown(KeyCode.Space)) { if (audioSource.isPlaying) { audioSource.Pause(); } else { StartCoroutine(playAudio()); } } if (audioFileChanged) { StartCoroutine(ChangeClip()); } else if (audioClipChanged) { UpdateMediaInfo(); AudioProcessor.ResetValues(); ScreenRecorder.ResetValues(); AddImagesToGrid.ResetValues(); StartCoroutine(AudioProcessor.SetAudioData(false)); audioClipChanged = false; // Change of file during picture mode if (pictureToggle.isOn) { waitVideoModeToBeOn = true; pictureModeWasOnSoSwitchBack = true; pictureToggle.isOn = false; videoToggle.isOn = true; } else { StartCoroutine(playAudio()); } } if (waitVideoModeToBeOn) { if (videoToggle.isOn && !audioSource.isPlaying) { StartCoroutine(playAudio()); } waitVideoModeToBeOn = false; } UpdateFullscreen(); UpdateSprites(); UpdateRunningTime(); HideWhilePlaying(); UpdateDisableBtns(); IEnumerator playAudio() { // Wait to allow anything else finish e.g. introPanel, black rest colour, intensity yield return(new WaitForSeconds(0.2f)); if (firstTimePlay) { GetComponent <DestoryIntroPanel>().enabled = true; firstTimePlay = false; } audioSource.Play(); yield break; } }