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
1
Question by HolBol · Aug 08, 2010 at 02:45 PM · audiosound

Sound play on keydown and continue playing

I want to have a car horn on my car. I thought it'd be bast to use this script:

function Update () {
if (Input.GetKey(KeyCode.H)) {
audio.Play();
} else {
audio.Stop();
}
}

But it doesn't work; the audio just stutters. How can i get it that when you press and hold the key, the sound continues, rather that restarting itself?

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 3dDude · Aug 08, 2010 at 03:27 PM 0
Share

is the audio clip set to loop?

avatar image HolBol · Aug 08, 2010 at 07:57 PM 0
Share

already is ste to loop

1 Reply

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

Answer by Magnus Wolffelt · Aug 08, 2010 at 03:35 PM

Just check if it's already playing, and make sure it's set to be looped:

function Update () {
  if (Input.GetKey(KeyCode.H)) {
    if(!audio.isPlaying) {
      audio.loop = true;
      audio.Play();
    }
  } else {
    audio.Stop();
  }
}
Comment
Add comment · Show 4 · 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 HolBol · Aug 08, 2010 at 07:57 PM 0
Share

still won't work, it stops andd starts like a car alarm, what's happening?

avatar image HolBol · Aug 08, 2010 at 08:06 PM 0
Share

don't worry, that script worked, it was the audio loop not set up right.

avatar image MC HALO · Sep 23, 2010 at 03:53 AM 0
Share

hey, can anyone help me i am having some audio problems, basically i have a audio on my object which is footsteps. This audio plays when i press the z key which is the walk key. if i press and hold the key the sound plays fine but if i stop holding the key the sounds still carry's on playing until the end can you please help me.

avatar image EytanTKing · Jun 29, 2011 at 06:17 AM 0
Share

Thanks for the info it really helped!!!

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

1 Person is following this question.

avatar image

Related Questions

AudioServicesPlaySystemSound - iOS System Sounds from Unity 1 Answer

Voice Recording issue ?? 0 Answers

Synch clips with BPM 2 Answers

Play An Audio Clip When An Instantiated Object Collides 1 Answer

Activate sound without Pro filters 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