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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by MythN7 · Aug 22, 2013 at 06:52 PM · c#audiodestroywait

c# and game objects active state issues

hello, I've tried finding things online and either I'm not entering the right words into my query, or the hits don't quite fit my needs, and I cant see the link to making it such.

Basically, what I'm currently getting frustrated with is how to get game effects working on a proper linked structure, and not a per frame mash up. as in seamlessly running audio or bools that act as if you only had one effect going off as true.

I'm hoping to kill a few birds with this post, so if its not an easy answer ill break it into new questions with my script examples specifically.

1st is audio: I've tried AudioSource with several clips lined up. I've tried audio.clip = x and a for loop with an audio.clip array where I tried to base it on if audio.isplaying == false then audio.play. but no matter what I do, it always jumps threw the clips just like mashing the next track button on a stereo. the same is true for a sound effect attached to a getaxis input

2nd issue with audio and particle effects to be linked just as 1st issue. If I destroy the game object and have an explosion sound and particle effect at the time of boom, the audio and effect cut off when I destroy game object, but if I add a wait for seconds then the game object is still controllable and active till the effects are done and it then triggers the destroy game object.

So can you have the particle effect and audio do a single shot play which continues to finish its sequence after the destroy.

Thank you hope this was clear.

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
0

Answer by whydoidoit · Aug 22, 2013 at 07:00 PM

Ok so to your first point:

  • Playing a list of clips

Code like this perhaps:

 [RequireComponent(typeof(AudioSource))]
 public class PlayClips : MonoBehaviour
 {
     public AudioClip[] clips;
     
     void Start()
     {
         StartCoroutine(Play(clips));
     }
     
     public IEnumerator Play(IEnumerable<AudioClip> clips)
     {
         foreach(var clip in clips)
         {
             audio.clip = clip;
             audio.loop = false;
             audio.Play();
             yield return new WaitForSeconds(clip.length);
         }
     }
 }

To your second question - you should establish the particle effect and audio source as a separate object instantiated or positioned where the first one is when it is destroyed.

Comment
Add comment · 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

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

16 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

Related Questions

Distribute terrain in zones 3 Answers

How to destroy a gameobject by GameObject.Find 1 Answer

Multiple Cars not working 1 Answer

Audio Trigger 3 Answers

Every few seconds, play an audio clip 3 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