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 JohnWatson · Sep 05, 2013 at 09:37 AM · soundwalkingbce0077

Walking sound Script returns with Error: BCE0077

I'm new to unity and i have some Problems at creating a Script that plays a sound when pressing "w" "a" "s" "d" and stops it when releasing those. Here's the Script so far:

 #pragma strict
 var Sound : AudioClip;
 function Start () {
 
 }
 function Update () {
     if(Input.GetKeyDown("w"))(Input.GetKeyDown("a"))(Input.GetKeyDown("s"))(Input.GetKeyDown("d"));{
         audio.clip = Sound;
         audio.Play();
     }
 
     if(Input.GetKeyUp("w"))(Input.GetKeyUp("a"))(Input.GetKeyUp("s"))(Input.GetKeyUp("d"));{
         audio.Stop();
     }
     
 }

This keeps returning with the error: it is not possible to invoke an expression of type 'boolean' (BCE0077)

I would apreciate any help and also if somebody could tell me how to make the sound stop if i jump tat would be nice too. Thanks in advance!

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 FrankStarsKo · Sep 05, 2013 at 10:22 AM

just replace your code with this, and attach your audio source to the game object

 #pragma strict
 
 @script RequireComponent(AudioSource)
 function Start () {
  
 }
 function Update () {
     if(Input.GetKeyDown("w")||Input.GetKeyDown("a")||Input.GetKeyDown("s")||Input.GetKeyDown("d"))
     {
       audio.Play();
     }
  
     if(Input.GetKeyUp("w")||Input.GetKeyUp("a")||Input.GetKeyUp("s")||Input.GetKeyUp("d"))
     {
        audio.Stop();
     }
 }


Hope this is what you wanted.

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 JohnWatson · Sep 05, 2013 at 11:23 AM 0
Share

Thanks for the quick answer but the Script doesn't allow me to bind in an Audio clip.. or am i missing something ?

Edit: got it fixed by making a variable... now the only problem is the sound restarts everytime I press another button ex. I'm holding down "w" the sounds starts playing then I don't let go of "w" but I also start holding "d" then the sound restarts any way around that ?

avatar image FrankStarsKo · Sep 05, 2013 at 09:17 PM 0
Share

i tested the script before i sended to you, and i saw there was not need to make the variable (if you just added, it is there with no use) you can safely leave it as i gave it to you,

in the other hand, maybe your sound is too long, try to cut your sound to only 1 step in the file, after doing that go to your gameobject that holds the audiosource and set to "loop" checked and "Play On Awake" uncheked inside the inspector tab.

one last thing, if you want to make your sound to stop while jump, i think it would be easier to mix the script i gave you with your character controller script so you can be able to check for the condition "isGrounded"

 if (controller.isGrounded)
         {
               audio.Play();
           }

otherwise your code is going to turn too complex to follow. @_@ cheers.

avatar image
0

Answer by robhuhn · Sep 05, 2013 at 09:56 AM

You missed the logical operators in your condition, closed the bracked too early and have a semicolon behind the if statement.

Here are a few examples of logical operators:

AND

OR

NOT

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 JohnWatson · Sep 05, 2013 at 11:23 AM 0
Share

Thanks alot, could you please elaborate where i have an ; to much and where i ned to reset the Bracket (and do you mean these () or {}?)

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

18 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

Related Questions

help sound on collision when key down 2 Answers

Why my sound it's not attaching to my Flashlight 2 Answers

Stop another sound from another script? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to play Audio Once if enemy has enterd a trigger 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