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 Borr1310 · Nov 21, 2016 at 07:38 PM · audioaudiosourcecomponentcomponentsaudio.play

Weird audio problem

What the hell?? So first off I want to say that there is probably nothing wrong with the code. Today I was working on my project. I was trying to add sound effects to my other objects.. And I did. And then suddenly 2 errors popped up. On both of these errors I was basically trying to play Audio through script.

'AudioSource' does not contain a definition for 'clip' and no extension method 'clip' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?

'AudioSource' does not contain a definition for 'Play' and no extension method 'Play' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?)

Here is my code but again, there is 100% nothing wrong with it since it worked fine before. Also its not completely the same as I changed it a bit after trying to solve the problem. But either way the script is probably alright.

 public void ChangeLevel()
     {
         StartCoroutine(delayedLoad());
     }
 
     private IEnumerator delayedLoad()
     {
         AudioSource audio = GetComponent<AudioSource>();
         audio.clip = OtherClip;
         audio.Play();
         Player.SetActive(false);
         FadeOutPanel.SetActive(true);
         FadeOutAnim.enabled = true;
         yield return new WaitForSecondsRealtime(0.45f);
 
         SceneManager.LoadScene(0);
     }

So does anyone have any idea how could these errors just pop up after adding couple AudioSource components to gameobjects?

Thanks.

UPDATE!!

If I try...

  AudioSource audio = GetComponent<AudioSource>();
         if(audio == null)
         {
             print("AUDIO NOT RECOGNIZED");
         }
         else if(audio != null)
         {
             print("AUDIO RECOGNIZED");
         }

it prints message AUDIO NOT RECOGNIZED, that means that even though Audio source component is attached it doesnt recognize it.

Comment
Add comment · Show 2
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 oStaiko · Nov 21, 2016 at 09:38 PM 0
Share

Does your script have

 using UnityEngine.Audio;

at the top? That would do it.

avatar image Borr1310 oStaiko · Nov 22, 2016 at 12:13 PM 0
Share

Doesnt make a difference. Again, it worked before and I didnt modify the script at all.

1 Reply

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

Answer by tanoshimi · Nov 22, 2016 at 12:29 PM

Did you by any chance rename your script as AudioSource.cs?

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 Borr1310 · Nov 22, 2016 at 12:36 PM 0
Share

Woah, just as I fixed the problem you answered it, exacly. When I was adding Audio Source gameobjects I ins$$anonymous$$d added a script named Audio Source by a mistake. Just realized that thanks either way!

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

70 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

Related Questions

master background music toggle not working after changing scenes 1 Answer

Audiosource.Play() not working 0 Answers

audio.Play(); not working while audio.Stop(); works fine when the audio is played on awake 1 Answer

AudioSource.clip.time won't work? 2 Answers

Assign a clip to an AudioSource when it finishes playing. 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