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 /
avatar image
1
Question by DibonaJ · May 13, 2011 at 01:46 PM · guiraycastsoundselection

Advance when the sound is done playing

Hello everyone. I have encountered a problem that I have not been able to figure out after a few days of tweeking things around. Right now I have a scene where you are taken from point to point, like a rail shooter. At each point you click on objects to learn about them, and some of them even have sound. After you click on each object a question pops up. My problem is that the question pops up right when you click on an object, even if that object has a sound attached to it. If the object has a sound attached to it I would like the sound to finish before the question pops up. The sound is attached to one object and the script to pop up the question is attached to another. Is there a way to determine if the sound on another object is finished playing? I will attach a bit of my script for the clicking on objects and the question popping up:

if(hit.collider.gameObject.name == "oilDriBag")
                    {
                        GameObject oildribag = GameObject.Find("oilDriBag");
                        oildribag.GetComponent<AudioSource>();
                        if(audio.isPlaying)
                        {
                            audioIsPlaying = true;
                        }
                        if(!audioIsPlaying)
                        {
                            object1Clicked = true;
                        }
                    }

That part is in the update function. The onGUI function has the code for popping up the question. It simply just draws boxes and buttons, but I don't want that to happen until the sound has finished playing from the objects clicked in the code above.

EDIT: I have put in the code that I have now, but I am obviously doing something wrong.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by DaveA · May 13, 2011 at 02:50 PM

Two things come to mind 1. There is an 'isPlaying' member on the audio class, which you can monitor. Let it go true first to make sure it's playing, then watch for it going false. 2. You can find out the length of the clip and use that as a timer (don't allow click until that amount of time has elapsed).

http://unity3d.com/support/documentation/ScriptReference/AudioSource-isPlaying.html

Comment
Add comment · Show 5 · Share
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
avatar image DibonaJ · May 13, 2011 at 03:28 PM 0
Share

How would I check if audio isPlaying on another gameObject from a script other than the one that controls my camera? I tried checking for it before but since it is attached to another game object using another script I don't know how to check for it.

avatar image DaveA · May 13, 2011 at 03:40 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/index.html and click on Accessing Other Components (the rest of those links are good reading too!)

avatar image DibonaJ · May 13, 2011 at 04:12 PM 0
Share

I'm still not grasping the concept. I'll get there eventually, but not there yet. I have updated my code to show you what I have, but it still isn't working right. I get an error saying "There is no AudioSource on main camera but a script is trying to access it" I want to get the AudioSource from the oilDriBag game object though, not the main camera. Any idea what my mistake is?

avatar image DaveA · May 13, 2011 at 08:54 PM 0
Share

You get the audio source but you don't do anything with it. Assign it to a var, then check it's isPlaying: var aud = oildribag.GetComponent(); if (aud.isPlaying) etc etc

avatar image DaveA · May 13, 2011 at 08:55 PM 0
Share

Also, you don't need to do a Find, you already have the game object on the 'hit': hit.collider.gameObject.GetComponent()

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

No one has followed this question yet.

Related Questions

GUI Box not showing up after object clicked 1 Answer

raycast with transparent shader 1 Answer

Saving selections across multiple menus? 1 Answer

Vertical distance indication 1 Answer

How do disable uGUI/EventSystem selection feature? 0 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