• 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
0
Question by JudyNails · Jul 05, 2010 at 07:44 PM · audioplayordersequenceconcat

How to string multiple audio clips together

Hi guys,

I need to string three audio clips together to give a score at the end of the game. For example, I've got a clip which says "You've got", several with a number - e.g. "two" and finally "stars!".

Obviously, the number audio clip is the player's score, stored as an int variable. Would any of you clever people be able to suggest how I can play each in turn so that it sounds like a sentence?

I've only been using Unity for a couple of weeks (and programming for as long!), so be gentle with me!

Many thanks

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
3
Best Answer

Answer by fherbst · Jul 05, 2010 at 08:15 PM

You can use something like this:

var startClip: AudioClip; // make sure to attach all your number audio clips here var numberClip:AudioClip[]; var endClip: AudioClip;

function PlayNumberSound(i : int) { audio.clip = startClip; audio.Play(); yield WaitForSeconds (audio.clip.length); audio.clip = numberClip[i - 1]; // i-1 because array starts at 0 audio.Play(); // you can probably leave this one out yield WaitForSeconds (audio.clip.length); audio.clip = endClip; audio.Play(); // you can probably leave this one out yield WaitForSeconds (audio.clip.length); audio.Stop(); }

function Start() { // Should play startClip + numberClip[5-1] + endClip PlayNumberSound(5); }

I haven't tested it, but it might work :).

Comment
Add comment · Show 1 · 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 JudyNails · Jul 08, 2010 at 08:36 PM 0
Share

Thank you Felix, you clever chap! I really appreciate this. It works perfectly (after I remembered to attach an audio source to the game object the script was attached to!). Now I need to work out some way of accessing the array based on the value of a string variable!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

AudioClip Import Order Randomized? 4 Answers

Play next song 1 Answer

Play Audio Sound OnTriggerEnter 2 Answers

How can I combine multiple audio clips to form one audio clip? OR another method to control a string of audioclips as one. 0 Answers

Stream multiple audio files 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges