x


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?

more ▼

asked Oct 27 '11 at 06:23 AM

Annihilator51209 gravatar image

Annihilator51209
1 1 1

Seriously, instead 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.

Oct 27 '11 at 07:07 AM syclamoth

Aye, when it comes to programming, 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 performing poorly, but written by ME 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. :)

Oct 27 '11 at 09:49 AM CHPedersen
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It's pretty simple:

  • add an audiosource to your truck instance <= this is the object responsible for managing audio events.
  • 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.
more ▼

answered Oct 27 '11 at 08:55 AM

roamcel gravatar image

roamcel
1.2k 37 40 44

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1950
x1027
x532
x523

asked: Oct 27 '11 at 06:23 AM

Seen: 460 times

Last Updated: Oct 27 '11 at 09:49 AM