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 /
This question was closed Jan 23, 2015 at 08:42 AM by meat5000 for the following reason:

Duplicate Question

https://www.google.co.uk/search?q=unity+play+a+sound&ie=utf-8&oe=utf-8&gws_rd=cr&ei=SwnCVMvGAqm07gaRs4GIDQ#q=unity+play+a+sound+enemy+death

avatar image
0
Question by KenjiHyorinmaru · Jan 23, 2015 at 07:30 AM · explosionsfx

Based on my (C Sharp ) code, how would I add my explosion sound when i destroy the enemy?

 // The speed to use when in "ramming" mode
     [SerializeField] float RamSpeed = 5.0f;
 
     // The different IDs fo the AI states
     enum AIMode {Normal, Ramming, SteerTowards, Charge, Avoid };
 
     // The variable which holds the current AI state
     private AIMode CurrentAIState;
 
     // List of pickup TYPES to spawn
     [SerializeField]GameObject[] PickupTypes;
 
     // Holds the audio clip to play
     // when this object is spawned
     [SerializeField]AudioClip EnemyDestSfxClip;
 
     // The particle system to spawn when the 
     // projectile collides with something.
     [SerializeField]GameObject EnemyParticles;
 
     // The game object which spawned us.
     private ShipPlayerController PlayerShipCtrl;
 
     // Used to control how fast the game object moves
     [SerializeField] float MoveSpeed = 3.0f;
 
     // Instantiates a particle when something is hit.
     // Represents the "death of THIS game object, not
     // the desruction of what the projectile hit.
     void SpawnEnemyParticles()
     {
         Instantiate (EnemyParticles,
                      transform.position, transform.rotation);
     }
 
 
     // A customized version of the destroy function
     void StartDestroy(float timeDelay)
     {
 
         // Turn off drawing and colliding
         renderer.enabled = false;
         collider.enabled = false;
         // Start the destroy countdown
         Destroy (gameObject, timeDelay);
 
     }
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 KenjiHyorinmaru · Jan 23, 2015 at 03:44 AM 0
Share

how to make it, when i shoot the enemy ship and it explodes, i wanna hear the explosion sound as it explodes, really confuse on that part

2 Replies

  • Sort: 
avatar image
1

Answer by sniper43 · Jan 23, 2015 at 08:38 AM

http://docs.unity3d.com/ScriptReference/AudioSource.PlayClipAtPoint.html

Use this. Creates a new GameObject (which has no body, is only an audiosource) and you can freely destroy your enemies while retaining the 3D position of the sound (the Audio self-destructs on completion).

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 JustinC · Jan 23, 2015 at 07:39 AM

Add a Public AudioClip explode; then in your void StartDestroy function add explode.Play()

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 sniper43 · Jan 23, 2015 at 08:37 AM 0
Share

This doesn''t work, as it destroys the auido source as well. I posted an answer below.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I make particles respect the rotation of objects, and fix error "!IsFinite(outDistanceForSort)" 2 Answers

Explosion problem 1 Answer

unknown identifer explosion problem 2 Answers

Unity Explosion Framework didn't work 0 Answers

Bullets wont collide and destroy object 1 Answer


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