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
0
Question by jjoohhnnyy13 · Mar 11, 2019 at 04:25 PM · unity 5collisionobjectsound

the sound will not play

Hi, please guys, i am frustrated, i work over 3 days... i have two objects (rocket and asteroids) every objects have script destruction-collision Code: public class DestroyByContact2 : MonoBehaviour {

 public GameObject explosion; 


 void OnCollisionEnter()
 {
     GameObject expl = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;


     Destroy(gameObject); 
     Destroy(expl, 2); // (expl, delete the explosion after... seconds)

 }

}

and now, i have problem create sound explosion...i created new script with name "Sound" and i inserted his code in to Rocket, his code Code: public class Sound : MonoBehaviour { public AudioClip impact; public AudioSource audioSource;

 void Start()
 {
     audioSource = GetComponent<AudioSource>();
 }



 void OnCollisionEnter(Collision collision)
 {

     if (collision.gameObject.tag == "Asteroids")
     {


         audioSource.PlayOneShot(impact, 0.7F);

     }

 }

} i have something bad? My goal is, when rocket crash into asteroids so it is created explosion with sound explosion.

Comment
Add comment · Show 3
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 CybexGS · Mar 14, 2019 at 12:47 PM 0
Share

Hey, i tried to answer your question with the switching scenes / explosion / delay problem but the question was gone before i could post my comment... idk why...

avatar image jjoohhnnyy13 CybexGS · Mar 14, 2019 at 01:26 PM 0
Share

I don't know, it was probably blocked because of duplicity, although I didn't find anything like that ...

avatar image CybexGS jjoohhnnyy13 · Mar 14, 2019 at 01:41 PM 0
Share

If i remember correctly you were trying to check an objects existence in its update method although you've already destroyd it through a collision check. This doesn't work.

You want an object that doesn't exist anymore to check if it exists or not. That's kind of paradox.

I obviously can't see your code anymore, just post it here again and i'll try to help.

2 Replies

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

Answer by xxmariofer · Mar 11, 2019 at 04:46 PM

probably the asteroids are far away from thje camera and the sound is not being heared? try this code

 AudioSource.PlayClipAtPoint(impact, new Vector3(0, 0, Camera.main.transform.position));
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 jjoohhnnyy13 · Mar 11, 2019 at 05:00 PM 0
Share

GREEEEEEAT, GOD BLESS YOU

avatar image
0

Answer by CCnockaert · Mar 14, 2019 at 03:46 PM

 Destroy(gameObject); 
      Destroy(expl, 2); // (expl, delete the explosion after... seconds)

Nothing to do with your problem but if you destroy this.gameObject then it'll never Destroy the expl gameObject.

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

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

Related Questions

How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer

How do i prevent the player from dragging a ui element off screen? 1 Answer

Is possible to use UISprite object of NGUI with event type 2D to detect intersection? 0 Answers

Dice roll collision sound 1 Answer

Sphere (player) flattens/deforms when going on a moving platform. 0 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