Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created August 23, 2020 11:59
Show Gist options
  • Save aiya000/b77668748e319b375d18bb30f63a4c7e to your computer and use it in GitHub Desktop.
Save aiya000/b77668748e319b375d18bb30f63a4c7e to your computer and use it in GitHub Desktop.
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class PlayPauseAudioSource : UdonSharpBehaviour {
public AudioSource audio;
private bool hasPlayed = false;
public override void Interact() {
if (this.audio == null) {
Debug.Log("The audio has not set.");
return;
}
if (!this.hasPlayed) {
this.audio.Play();
this.hasPlayed = true;
return;
}
if (this.audio.isPlaying) {
this.audio.Pause();
return;
}
this.audio.UnPause();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment