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 kingari · Dec 15, 2014 at 01:35 AM · audioaienemy

Unity 3D Audio Clip Disabled

Hello,

I am attempting to make a sound clip play when I destroy an enemy in a space shooter type game. However it keeps giving me the following message: Can not play a disabled audio source UnityEngine.AudioSource:PlayOneShot(AudioClip) EnemyControllerBasic:OnTriggerEnter(Collider) (at Assets/Stewart_Tafari_Lab2/Scripts/EnemyControllerBasic.cs:36).

Any idea why it is doing this?

using UnityEngine; using System.Collections;

public class EnemyControllerBasic : MonoBehaviour {

 // The game object which spawns us. 
 private ShipPlayerController PlayerShipCtrl;
 // The game object which spawns the projectile.
 private Mover Bolt;
 // The different IDs for the AI states
 enum AIMode { Normal, Ramming, SteerTowards, Charge };
 // The variable which holds the current AI state
 private AIMode CurrentAIState;
 // Holds the audio clip to play when 
 // this object is destroyed
 [SerializeField]AudioClip blowupSfxClip;
 // List of pickup TYPES to spawn
 [SerializeField]GameObject[] PickupTypes;
 // Used to control how fast the game object moves
 [SerializeField]float MoveSpeed = 4.0f;
 // The speed to use when in "ramming" mode
 [SerializeField]float RamSpeed = 5.0f;
 // The speed to use when in "charge" mode
 [SerializeField]float ChargeSpeed = 6.0f;

 // Called by the engine when this object collides
 // with another object containing collision
 void OnTriggerEnter (Collider other) {
 
     // Hit the player's projectile?
     if (other.tag == "PlayerProjectile") {
                     
                     // A projectile= instant kills us
                     Destroy(gameObject);
                     // play the blowup audio sfx file
                     audio.PlayOneShot(blowupSfxClip);
                     // Drop a pickup
                     SpawnPickup ();

         }
     // Hit the player's ship?
     else if (other.tag == "PlayerShip") {
                     
                     // Wrecking with the player kills us
                     Destroy(gameObject);
     
                     // Remove points from the player for hitting the enemy
                     PlayerShipCtrl.ModScore (-1);

                     // Remove shield from the player for hitting the enemy
                     PlayerShipCtrl.ModShield (-1);
                     
                     // Remove health from the player for hitting the enemy
                     PlayerShipCtrl.ModHealth(-1);
             }
         
 }
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
0

Answer by ahmedbenlakhdhar · Dec 15, 2014 at 01:42 AM

Here:

 Destroy(gameObject); //You destroy the game object
 audio.PlayOneShot(blowupSfxClip);//You use its audio source component after its destruction

You cannot use the audio attribute of a destroyed game object.

Try to play the audio in another audio source of an enduring game object.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

AI enemy scripting help 1 Answer

How do I make ai play a certain sound, and then make the other ai reply? 0 Answers

Shooting Damage Help 1 Answer

Stay Back! 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