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 Eizdieler · Oct 25, 2012 at 10:31 AM · audiosourcerequirecomponent

@script RequireComponent(AudioSource) does not work

Hi,

I´m going through the Unity Game Dev Essentials right now and having a little problem with the

@script RequireComponent(AudioSource)

command.

It simply doesn´t work. In Chapter 8, there is this simple script:

 var levelToLoad : String;
 var normalTexture : Texture2D;
 var rollOverTexture : Texture2D;
 var beep : AudioClip;
 
 function OnMouseEnter(){
     guiTexture.texture = rollOverTexture;
 }
 
 function OnMouseExit(){
     guiTexture.texture = normalTexture;
 }
 
 function OnMouseUp(){
     audio.PlayOneShot(beep);
     yield new WaitForSeconds(0.35);
     Application.LoadLevel(levelToLoad);
 }
 
 @script RequireComponent(AudioSource)

which should add an Audio Source component to an object, after the script is added. Well, it doesn´t work for some reason and I can´t find out why. Anyone knows what could cause it not to appear in the inspector ? :(

Thanks for help in advance !

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 Eizdieler · Oct 25, 2012 at 01:21 PM 0
Share

Hmhmh no. I´ve seen that sometimes it works, sometimes not. I have created a new GameObject to test it and yea...didn´t work again.

avatar image Paul-Sinnett · Oct 25, 2012 at 01:46 PM 0
Share

In the situations where it didn't work, did it just fail to add the audio source, or did it fail to add the script as well?

I copied the code posted above and tested it a few times. It appears to work reliably. I'm not sure why it's not working for you.

1 Reply

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

Answer by Paul-Sinnett · Oct 25, 2012 at 12:48 PM

Did you already have the script attached before adding the RequireComponent line? I think it only adds the object at the point the script is applied to the object.

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 Psychonerd · Apr 17, 2013 at 07:16 PM 0
Share

@Paul Sinneti that seems true. I had the same problem, detached the script, attach it again after adding the RequireComponent and it included the Audio Source

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

11 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

Related Questions

Does not work: @script RequireComponent(AudioSource) 0 Answers

What is the script code on how to trigger a song for the player to Listen to? 2 Answers

Assertion failure in AudioManager.cpp? 2 Answers

There is no 'AudioSource' attached to the 4 Answers

Multiple AudioSources overwriting a looping AudioSource 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