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
0
Question by Ryan 8 · Apr 22, 2011 at 10:49 PM · collisionaudiosourceaudioclip

Playing an audio clip

I want an audio clip to play when two cars collide but I can't make it so the audio doesn't play at the beginning. If it doesn't play then, then it won't play at all. Any suggestions as to how I can script this. I can't figure out anything that doesn't give me an error.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Caiuse · Apr 22, 2011 at 11:15 PM

making sure theres an 'audio source' component attached to the object that has this script.

var myClip : AudioClip;

function OnCollisionEnter(collision : Collision) { audioClip = myClip; audioPlay(); }

I havent tested it, but it's along those lines.

  • C
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 Ryan 8 · Apr 23, 2011 at 02:32 AM 0
Share

I kept trying variations of this code and eventually realized that an audio source component needed to be attached to the oject that has the script like you said. I also noticed that it had to be added before the script componenent was added. Thanks for that tip.

avatar image
0
Best Answer

Answer by MC HALO · Apr 23, 2011 at 02:05 AM

hey if you want to play an audio source you can do the following:

var MyAudioClip : AudioClip;

function OnCollisionEnter (hit:Collision ){

AudioSource.PlayOneShot(MyAudioClip, transform.position );

}

if you want the sound to be 2 dimensional make sure that in unity when you drag the audio clip in to the inspector look for it and click on it. once you do that a list of options will become available on the sound look for where it says 3d sound tick that of and hit apply. The reason this is important is because if you leave 3d sound on and you move the player the sound starts to fade away when you are far away from the trigger :)

hope this helps.

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
avatar image
0

Answer by Aydan · Apr 22, 2011 at 11:11 PM

Let Sound Clip wait for x seconds before sounding

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
avatar image
0

Answer by IndieForger · Feb 08, 2013 at 02:37 PM

You might want to check this post if you have sound related issues.

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

1 Person is following this question.

avatar image

Related Questions

Adding sound javascript in unity2d 1 Answer

Audio won't play on collision 0 Answers

Can play multiple sounds from one audiosource on an object. But cant play sound from audiosource on another? 0 Answers

OnTriggerExit stop audio 1 Answer

How to generate waveform from AudioClip? 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