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 Ian-McCleary · Jun 10, 2015 at 09:48 PM · javascripterroraudiocalling

Error UnityEngine.Component.audio is obsolete.

I received a few errors when i am using this script trying to get audio to work, and i think it has to do with using the old version of unity before. Here they are

Assets/Scripts/Shooting.js(69,25): BCE0144: 'UnityEngine.Component.audio' is obsolete. Property audio has been deprecated. Use GetComponent() instead. (UnityUpgradable)

Assets/Scripts/Shooting.js(69,31): BCE0019: 'playOneShot' is not a member of 'UnityEngine.Component'.

I dont know what is going on, but if there is another way to play the audio that would be great.

 function Shoot(){
     while(true){
         if(shooting == true && weaponnum == 0 && rbullets1 > 0){
             rbullets1--;
             audio.playOneShot(aeksound, 1.0);
             Physics.Raycast(transform.position, transform.forward.hit);
             Debug.Log(hit.collider.tag);
                 if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                     Destroy(hit.transform.gameObject);
             }
         }
                 else if(weaponnum == 0 && rbullets1 == 0){
                     yield WaitForSeconds(2);
                     if(rbullets >= 30);
                         rbullets -= 30;
                         rbullets1 += 30;
             }
             else if(rbullets < 30){
                 rbullets1 += rbullets;
                 rbullets = 0;
             }
         }
         if(shooting == true && weaponnum == 1 && pbullets1 > 0){
             pbullets1--;
             audio.playOneShot(walthersound, 1.0);
             Physics.Raycast(transform.position, transform.forward.hit);
             Debug.Log(hit.collider.tag);
                 if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                     Destroy(hit.transform.gameObject);
             }
         }
                 else if(weaponnum == 1 && pbullets1 == 0){
                     yield WaitForSeconds(2);
                     if(pbullets >= 30);
                         pbullets -= 30;
                         pbullets1 += 30;
             }
             else if(pbullets < 30){
                 pbullets1 += pbullets;
                 pbullets = 0;
         }
 }

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

2 Replies

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

Answer by Ian-McCleary · Jun 12, 2015 at 02:34 AM

To those looking for the answer. This worked just fine.

 AudioSource.PlayClipAtPoint(walthersound, transform.position);

I dont know if it allows others to hear the audio though.

@Bunny83 also stated that i didn't capitalize the P in Play. This function also works

 GetComponent(AudioSource).PlayOneShot(aeksound, 1.0);


Comment
Add comment · Show 2 · 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 Bunny83 · Jun 12, 2015 at 03:08 AM 0
Share

Note that PlayClipAtPoint creates a temporary AudioSource to play the sound. As it's a static method it's not bound to a certain gameobject. When the clip has been played the temporary AudioSource is destroyed.

avatar image Ian-McCleary · Jun 12, 2015 at 03:26 AM 0
Share

@Bunny83 Yes, i noticed this. Thank you for posting that last reply of yours. I didn't realize it changed it that much and i also didn't realize that i didn't capitalize The P in Play. Thank you for your help!

avatar image
1

Answer by crohr · Jun 10, 2015 at 09:58 PM

That is just telling you to use GetCommponent()

Comment
Add comment · Show 5 · 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 crohr · Jun 10, 2015 at 10:00 PM 0
Share

whoops my code didn't show up:

 GetComponent<AudioSource>().playOneShot(aeksound, 1.0);
avatar image Ian-McCleary · Jun 10, 2015 at 11:31 PM 0
Share

After changing it, I get these set of errors in the two different places that i changed the code.

Assets/Scripts/Shooting.js(49,51): BCE0043: Unexpected token: ).

Assets/Scripts/Shooting.js(49,52): BCE0044: expecting ), found '.'.

Assets/Scripts/Shooting.js(49,53): UCE0001: ';' expected. Insert a semicolon at the end.

Now i do have semicolons and to prove it, here is my code. $$anonymous$$aybe i wrote something else wrong?

 function Shoot(){
     while(true){
         if(shooting == true && weaponnum == 0 && rbullets1 > 0){
             rbullets1--;
             GetComponent<AudioSource>().playOneShot(aeksound, 1.0);
             Physics.Raycast(transform.position, transform.forward.hit);
             Debug.Log(hit.collider.tag);
                 if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                     Destroy(hit.transform.gameObject);
             }
         }
                 else if(weaponnum == 0 && rbullets1 == 0){
                     yield WaitForSeconds(2);
                     if(rbullets >= 30);
                         rbullets -= 30;
                         rbullets1 += 30;
             }
             else if(rbullets < 30){
                 rbullets1 += rbullets;
                 rbullets = 0;
             }
         }
         if(shooting == true && weaponnum == 1 && pbullets1 > 0){
             pbullets1--;
             GetComponent<AudioSource>().playOneShot(walthersound,1.0);
             Physics.Raycast(transform.position, transform.forward.hit);
             Debug.Log(hit.collider.tag);
                 if(hit.collider.tag == "Player" || hit.collider.tag == "Vehicle"){
                     Destroy(hit.transform.gameObject);
             }
         }

avatar image Bunny83 · Jun 10, 2015 at 11:46 PM 0
Share

@Ian $$anonymous$$cCleary: You use UnityScript and not C#. You have to use

 GetComponent.<AudioSource>().xxxxxx

Note the ":" right after GetComponent. However in UnityScript you can even simply use:

 GetComponent(AudioSource).xxxxxx

@crohr:
There's an edit button below your answer ^^

avatar image Ian-McCleary · Jun 11, 2015 at 01:45 AM 0
Share

@Bunny83 So would it look like GetComponent(AudioSource).aeksound; ? because trying this does not work. nor does GetComponent.().aeksound

I now get this error Assets/Scripts/Shooting.js(49,54): BCE0019: 'aeksound' is not a member of 'UnityEngine.AudioSource'.

Im still getting used to the way all the functions work

$$anonymous$$y two sound variables are defined as var aeksound : AudioClip; var walthersound : AudioClip;

avatar image Bunny83 · Jun 12, 2015 at 03:18 AM 0
Share

@ian-mccleary:

Uhm why do you have changed your code completely? GetComponent returns a reference to the AudioSource component that is attached to the same object as your script. In the past there was the "audio" property which has done this under the hood for you.

So ins$$anonymous$$d of audio.xxxx you use GetComponent(AudioSource).xxxx where "xxxx" is of course whatever you want to access from the AudioSource component.

For example "PlayOneShot". Note that method names usually start with a capital letter so your "playOneShot" doesn't exist at all, not in the current version of Unity, neither in an older version.

 GetComponent(AudioSource).PlayOneShot(aeksound, 1.0);

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

22 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

Related Questions

Calling a function from another script issue 1 Answer

error javasript 1 Answer

How am I getting this error?? 1 Answer

Confusing Error 1 Answer

UnauthorizedAccessException during compilation 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