Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Peremy · Jul 29, 2020 at 01:55 PM · coroutineaudiosourceaudioclip

How would I check if an audioclip assigned to another object is playing?

Basically, I need to check if an audioclip is playing on another object so that I can use it to activate a coroutine. I'm basically not sure how I grab the audiosource, and check if the clip is playing. I'm also a bit of a newbie still and i feel this should be easy to figure out but I've really got no idea!! If anyone has any thoughts I'd really appreciate the input, thank you!

Here is the script that plays said audio - I only want it played once, hence why I'm using PlayOneShot with the audiosource assigned to the object as a component.

 public class PlayMarmion : MonoBehaviour
 //put on GoblinGo object to play Marmion extract reading sequence
 {
 
     public AudioSource poem2;
     public AudioClip creepy;
     AudioSource creepyVocals;
     
     public GameObject scottAnno;
 
 
     void Start()
         {
             creepyVocals = GetComponent<AudioSource>();
         }
 
 
     private void OnMouseDown()
         {
             Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray2) & CompareTag("Goblin"))
 
             {
                 creepyVocals.PlayOneShot(creepy, 0.05f);
                 poem2.PlayDelayed(8);
 
                 scottAnno.SetActive(true);
                 
             }   
 
         }
 
 }

and here is the script im trying to check the audio with - it's assigned to a piece of UI i want to fade so I need to check if the audio is playing before I start the coroutine:

 public class FadeSpookyBorder : MonoBehaviour
 //attach to SpookyBorder
 
 {
     // Start is called before the first frame update
 
     public CanvasGroup uiElement;
 
     public GameObject spookyBorder;
     private Animator animator;
 
     public GameObject goblinGO;
 
     private float start = 0;
     private float end = 1;
     private float lerpTime = 3f;
 
     void Start()
     {
         animator = spookyBorder.GetComponent<Animator>();
         uiElement = GetComponent<CanvasGroup>();
         goblinGO = GameObject.FindWithTag("Goblin").GetComponent<AudioSource>(); //I know this is incorrect and I'm not sure how to grab the clip
 
     }
 
     private void BorderFade()
     {
         if //some reference to if the audioclip is playing or not
         {
             //spookyBorder.SetActive(true);
             //animator.Play("SpookyEdgesAnimation");
 
             UIFader fader = Camera.main.GetComponent<UIFader>(); //UIFader script attached to main camera
             fader.StartCoroutine(fader.FadeCanvasGroup(uiElement, start, end, lerpTime));
         }
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

219 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio not playing when destroying a GameObject. 1 Answer

Determine end of audio clip if paused and resumed inbetween? 1 Answer

How can I improve audio quality with natcorder? 1 Answer

Stopping Audio When Zoomed In/Out 0 Answers

Why does AudioSource.time return Infinity in Unity 5.3? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges