Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 alex 1 · Apr 05, 2010 at 01:45 PM · physics

Engine noises creation

Okay so I want to create a racing game. I know its a bit of a stupid question, and i might be asking too much. but could somebody tell me a script that would be a bit like this

If car.speed = 10 then
play sound1
if car.speed = 20 then
play sound2 

abit like that, any ideas?

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

1 Reply

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

Answer by straydogstrut · Apr 05, 2010 at 02:18 PM

I think you're pretty much there with your pseudocode. Maybe something like this (untested):

// define variables for the car, speed and sounds // you will need to assign these in the editor var car : GameObject; var speed : int; var idleSound : AudioClip; var firstGearSound : AudioClip; var secondGearSound : AudioClip;

// initially set speed to zero function Start(){ speed = 0; }

function Update(){

if(speed==10){ // set the default audio clip to value stored in this variable audio.clip = firstGearSound;

} else if(speed == 20){ audio.clip = secondGearSound;

} else { audio.clip = idleSound; }

 // play the default audio clip
 audio.Play();

}

// make sure this gameobject has an audiosource attached for it to play sounds @script RequireComponent(AudioSource)

I don't drive so the first/second gear names are purely arbitrary! You'd probably want different sounds for gear changes and engine revs and it might be better to use speed ranges rather than fixed amounts. There's a detailed car tutorial here which you might find useful. I haven't actually tried switching sounds immediately like i'm suggesting above so you may find it isn't as smooth as you'd like. You might then have to look into crossfading between sounds for a smooth transition.

Good luck.

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 alex 1 · Apr 05, 2010 at 02:53 PM 0
Share

Just another question, Do you know how to make the speed change as time goes on, for example, i can only set my speed at the start, can i change it throughout? thanks!

avatar image straydogstrut · Apr 05, 2010 at 03:28 PM 0
Share

You would just set your speed variable when something happens, like input from the player, which you look out for in the Update function. If you wanted the speed to increase continually while the key is held down, just add to the speed variable (speed++ would increment by 1 each time for example). Look at Input.Get$$anonymous$$eyDown or Input.GetAxis in the scripting reference to get you started.

avatar image alex 1 · Apr 05, 2010 at 03:45 PM 0
Share

I'v looked at what you told me and cant seem to understand it very well. I'm quite new to unity so I'm really a noob. I used the tutorial you told me to use but didnt have much luck. The script you sent me was a success although i wanted to create a script that would change the speed over a time span. Could you be so kind as to tell me how to do it. I want it so that the top speed is a variable, so I can change it whenever I feel like. Thankyou so much! :D

avatar image straydogstrut · Apr 05, 2010 at 04:44 PM 0
Share

I'll be honest, i'm fairly new to Unity myself. I think it would be more helpful to you to look at some of the other threads on here which have links to car tutorials (just search for "car") since it probably won't be long before you get into rigidbodies and wheel colliders..things I know very little of. Googling just now I came across this tutorial - http://www.tutorius.net/2010/03/unity-racing-game-tutorial/ - which is specifically about creating a racing game so might be useful to you. Of course, feel free to ask further questions here, i'm sure someone will be able to help you=)

avatar image alex 1 · Apr 05, 2010 at 05:31 PM 0
Share

Thankyou very much (:

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

No one has followed this question yet.

Related Questions

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

Calcuation Difference Between AddForce and AddForceAtPosition 1 Answer

Effective 2.5D Seeker Missiles? 1 Answer

How do you make an item to use. 2 Answers

Dynamic Cube Physics like other games 0 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