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 Asle_Kinnerod · Mar 05, 2014 at 09:15 PM · instantiatetriggersound

Sound plays when instantiated and not on trigger.

I want my sound clip to play wen collision, but sound plays at the time the prefab the script is attached to is instantiated. Any ideas out there?? …please?? Here´s my code.

public class Collision : MonoBehaviour {

 public AudioClip crash;



 void OnTriggerEnter2D (Collider2D other){

     if (other.tag == "Player") {
      other.GetComponent<AddForce>().controll = true;
         AudioSource.PlayClipAtPoint(crash, transform.position);
         Destroy (other.gameObject, 3f);
         Application.LoadLevel ("Scene1");
         ScoreBoard.scoreP2 = 0;
     }
 }

}

Comment
Add comment · Show 1
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 highpockets · Mar 05, 2014 at 09:16 PM 0
Share

A script won't run on a game object that is not enabled. So, if it hasn't been instantiated, then the script will not run. You might want to call the sound from the other collider in the trigger

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · Mar 05, 2014 at 09:26 PM

Hi there

Does your prefab have an audio source attached with 'Play On Awake' set to true? If so that would cause it to play whatever sound was selected as soon as the object was instantiated.

Also, loading a level (which unloads anything you havent marked as 'dont unload') immediately after telling the sound to play seems a little dodgy to me. I can't say for certain it would cause problems, but if your sound is failing to play it might be worth seeing what happens if you remove that line of code.

-Chris

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 Asle_Kinnerod · Mar 05, 2014 at 09:41 PM 0
Share

Thanks Chris. That did it, and as you assumed, that level load had to be changed. Asle

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

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

Related Questions

Help Guitar Hero Style or similar 0 Answers

Trigger sound doesn't work 0 Answers

Trigger sound when walking through cube trigger 3 Answers

trigger sound by left mouse click ? 1 Answer

Get an object to play a sound if player rolls over a trigger. 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