Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TetroLancer · Dec 31, 2016 at 03:33 PM · c#audioaudiosourceaudioclip

Triggering multiple audio clips to play in sequence

Ok so I'm quite new to programming and all the rest and I'm just wondering how I'd go about programming something in C# alt text

so what's happening here is it's basically like a clock with four inner sections and three outer sections. I've made it so that the small hand completes a revolution in the time that the big hand passes through one section. I have it so that it lists it's location e.g. big hand: 1 small hand: 3, relative to what section each one is in.

How would I go about playing audio so that for example, when the big hand is in section 1, audio1 plays and when the small hand is in section 5, audio 5 plays after audio1?

I would have 7 audio clips, 1 for each section. How can I access them from script and how would I play the two audio clips in sequence?

Thanks for reading/answering and sorry if this is a dumb question or I've done messy work so far.

screen-shot-2016-12-31-at-151550.png (61.2 kB)
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
1
Best Answer

Answer by TheFloatingSheep · Dec 31, 2016 at 07:09 PM

I'm not quite sure how the syntax for this would go in C# so I'll just try to explain it rather than write the code:

You first need to make an array of AudioClip type variables, you can't change the length of an array like this at runtime but hopefully you won't need to do that. Then you go into the inspector, change the length to 7 in your case, and assign every clip in order. Then you use GetComponent to get the AudioSource component, assign one of your clips by typing = YourAudioClipArray[numberofclipcountingfrom0 - as integer obviously];

Now... from what I understand your script is counting from 1 to 7, computers always count from 0, so, basically your first audioclip will be name[0] instead of [1], based on the same logic 7 will be 6 and so on, so you could theoretically knowing on which segment the hand of your clock thing is, assign the item with that same number minus 1. Then use the play method of the audio source component.

Cheers.

Comment
Add comment · Show 2 · 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 TetroLancer · Jan 01, 2017 at 01:32 PM 1
Share

Thanks so much! That was extremely useful and well explained, I managed to figure it all out.

avatar image TheFloatingSheep TetroLancer · Jan 04, 2017 at 05:52 PM 0
Share

Glad I could help :)

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

8 People are following this question.

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

Related Questions

How to play "audiosource" component in a prefab from script? 0 Answers

How can I play audio clips depending on the players movement 0 Answers

Audio Clip Playing every frame 2 Answers

Audio/c#/unity Can i control the duration by time ? 1 Answer

PlayClipAtPoint Qualify with Type Name 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