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 Annihilator51209 · Oct 27, 2011 at 06:23 AM · audiosound

Vehicle help

I already asked this question before on another user, but i was kinda vague. My problem is is than i need a vehicle to make sounds. Plain and simple: i need a c# of java script file to tell the game to play a mp3 file called truck upon pressing w a s and d keys. I tried a guess at it:`#include truck.mp3 { if (Input.GetKeyDown("w")) { truck.mp3 = true; } if (input.GetKeyDown("w")) { truck.mp3 = false; }

i am posotive that is wrong, but it is my best shot lol. i tried it and it didn't work. also that's only for the w key. anyway can somebody help me?

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 syclamoth · Oct 27, 2011 at 07:07 AM 0
Share

Seriously, ins$$anonymous$$d of gessing like that, why don't you try reading the manual? This stuff is really, really basic- you should read through and absorb everything there is in the scripting reference, because there are code examples for everything you might want to do, and only come here when you have a question which isn't covered by that.

avatar image CHPedersen · Oct 27, 2011 at 09:49 AM 2
Share

Aye, when it comes to program$$anonymous$$g, danger begins when you start guessing. :) It actually takes a lot of discipline to never make "guesses", especially when you become just a little experienced and code starts flowing more easily. But as a cardinal rule: You must never write code that you "guess" is right. You must always know exactly what something does, and preferably exactly WHEN it does it.

I would rather have a shoddy piece of code, poorly written and perfor$$anonymous$$g poorly, but written by $$anonymous$$E so I understand it, than a well-written, complex function that runs fast, but that I copy-pasted, so it might use mathematics I don't understand, or language features I've never heard of. Why? Because I can fix and improve something I understand. If something I do later on breaks the code I copy-pasted in, I'll be helpless to fix it.

Does that mean you should never take and use the code others have written? No, certainly not. But it means you should never take and use the code others have written WITHOUT UNDERSTANDING IT FIRST. That last part is key, because it's how all programmers learn; we study each other's code. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by roamcel · Oct 27, 2011 at 08:55 AM

It's pretty simple:

  • add an audiosource to your truck instance

  • drag the truck audio clip into the audiosource's audioclip slot.

  • on 'input', use the audioclip property of the audiosource component to play, stop, etc.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Audio not playing [Fixed] 1 Answer

Wait for sound is played 2 Answers

play audio for few seconds on key hit 1 Answer

Sound on collision not working 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