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 avi_spc · Jun 16, 2017 at 05:21 AM · audioclipondisable

OnDisable() not working in case of audioclip.

I am trying to play an audio clip after the gameobject has been SetActive(false) that means after it is disabled. But I am not able to get any result. Audio clip is not playing after the gameobject has been disabled. Give me a solution.

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 AshAbeAdd · Jun 16, 2017 at 06:59 AM

How exactly are you doing this? Do you have public audioscripts attached to the script? Where do you have this script attach to, something that is permanent or temporary? For example if you have a main menu script, you could put in a public audio audioname; Set several different methods that get called in the script. Then in the section that you setactive(false) you can call a method to start the audio. However this all depend on how you're doing this. Make sure you're not disabling the script before you are calling the audio. Also make sure that the audio is being summoned. Put a Debug.Log(Audiotest); in there. However you need to make a bool for that and some codes.

Comment
Add comment · Show 6 · 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 avi_spc · Jun 16, 2017 at 08:06 AM 0
Share

my code is as follows:

if(box_count == 5){ GetComponent().PlayOneShot(enemy_death); enemy.SetActive(false); }

avatar image AshAbeAdd avi_spc · Jun 16, 2017 at 08:20 AM 0
Share

What about your audio? Is it in your code? There's a few things that I could say about the way you written your codes so far. I find it safer to not include symbols for variable, unless it's needed. Such as how namespace and hashtags are used. I'm a bit concerned about how you're using GetComponent() as well. You should read the definition and examples given by Unity. Last, I would recommend just activating and doing a check test on the audio within that if statement.

avatar image avi_spc · Jun 16, 2017 at 08:23 AM 0
Share

After the failure of previous script I tried this one:

if(box_count == 5){ enemy.SetActive(false); }

void OnDisable(){ GetComponent().PlayOneShot(enemy_death); }

where enemy_death is a public AudioClip and enemy is the public GameObject to which the script is attached.

but from this also I didn't get any fruitful result.

avatar image AshAbeAdd avi_spc · Jun 16, 2017 at 08:42 AM 0
Share

I'm not sure what it's called in Unity, but I believe your prototype is incorrect. If you're doing a 'public GameObject audioName;' Then that's the main error. Unless of course you have an audio attached to a Gameobject. The second word in this syntax is all about the type of value that you're adding. A gameobject would be anything such as a shape or a model. I believe audio is what you need for audio. You would have Texture, Image, and so on for the various items that you're trying to alter in the script that you're working in that body. In your new set of codes, I don't see a connection from the if statement to the OnDisable method. Plus it's a very horrible way of doing that, because you might want to disable other values.

avatar image avi_spc · Jun 16, 2017 at 08:33 AM 0
Share

Could you suggest me a better way of adding an audioclip after disabling the gameobject?

avatar image AshAbeAdd avi_spc · Jun 16, 2017 at 06:49 PM 0
Share

I decided to look back at one of my program and see what I had written for the audio source. We should make sure that you're actually playing the audio normally before putting it in a slightly more complicated location. Considering how hard it can be to find an actual pseudo for audio, I'll just give you one. AudioSource.PlayClipAtPoint(AudioFile, position); Insert your audio in the AudioFile and then you'll have several different options for position. I would recommend just using transform.position. Put this script in the Start() to see that you are loading in the audio.

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

68 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

Related Questions

Getting audio to play on collision 3 Answers

Play Audio x amount into the clip 3 Answers

Stop audiosource clip from playing 1 Answer

how to solve in this error "The name `CowboyRap' does not exist in the current context" .using below script 1 Answer

record dynamic length from microphone 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