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 theFTWnetwork · Dec 01, 2012 at 12:23 AM · javascriptaudioloopdelay

Audio loop after time

Ok, so i have a simple code:

Audio.clip = footstep; Audio.loop = true; Audio.Play();

Now, this starts the audio, and when it ends, it restarts it, but what i want is the audio to start, and after 3 seconds, start again (So before your audioclip is over, start a new one over it) The end of every audio clip has a fade out effect made in sony vegas, so when i get the script i'd like to have (after 3 seconds, restart but leave old one playing until its ended) it looks like the one is fading out while the other one plays.

This code could be complicated, so //messages are helpfull

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 code-blep · Dec 03, 2012 at 08:16 PM

Hi theFTWnetwork,

  1. I think you will need 2 audio sources

  2. Place them at the same spot

  3. Have each one loaded with the same sound clip

  4. Start one of them first, using the code you show above

  5. Start the second one but use yield WaitForSeconds (3); before the Audio.Play

Although I would personally use a clean looping clip of footsteps and use code to fade the sound out when required.

Hope it helps.

Paul

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
avatar image
0

Answer by Cashews · Sep 02, 2013 at 01:52 AM

I know this topic is old but I found a simpler way to solve your problem. I wanted an enemy to growl in intervals, but not have the growl be looped back to back. My solution was to use these two lines in Update():

 if(Time.time % 3f > 2.9f)
     audio.Play ();

It doesn't play in exact intervals (like exactly 3 seconds) but it loops pretty reliably. I'd recommend putting in Debug.Log(Time.time % 3f); to see how often it repeats, then change the two numbers to an interval closer to what you want. To avoid the sound clip stuttering and overlapping, make the second float very close to the first (About 0.1 or less of a difference)

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

13 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

Related Questions

My Footstep isn't working 2 Answers

A node in a childnode? 1 Answer

Blender Animation Looping Delay Problem 2 Answers

How do I prevent audio from restarting if it's being asked to play again? 2 Answers

How to make my music come on for a certain amount of time every few minutes 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