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 Amer ALhwifi · Nov 15, 2013 at 10:33 PM · audiolag

audio.PlayOneShot Lag !

Hello , Is there any fix to audio.PlayOneShot ? When the sound play , it play too slow :( Any idea ?

 using UnityEngine;
 using System.Collections;
 
 public class DestroyByScore : MonoBehaviour {
     public Score scoreScript;
     public AudioClip AmerFX;
 
     
     void Start()
     {
         //Find Scripts GameObject, and get Score Component.
         scoreScript = GameObject.Find ("Score").GetComponent<Score>();
     }
     
     void Update()
     {
         if(scoreScript != null && scoreScript.score >= 100)
             Destroy (gameObject);
             audio.PlayOneShot(AmerFX);
     }
 }

Thanks in advance!:)

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 AndyMartin458 · Nov 15, 2013 at 10:34 PM

If the audio is a compressed format like .mp3 or .ogg, that will always take longer to play. Make sure you are using .wav for any sound effects.

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 Amer ALhwifi · Nov 15, 2013 at 10:48 PM 0
Share

Thank you . It's a good point :) . The Solution was using AudioSource.PlayClipAtPoint The final script should be like this : using UnityEngine; using System.Collections;

 [RequireComponent(typeof(AudioSource))]
 public class Score : $$anonymous$$onoBehaviour
 {
     public int score = 0;                    // The player's score.
     public GameObject Amer;
     public AudioClip AmerFX;
 
     private PlayerControl playerControl;    // Reference to the player control script.
     private int previousScore = 0;            // The score in the previous frame.
 
 
     void Awake ()
     {
         // Setting up the reference.
         playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>();
     }
 
 
     void Update ()
     {
         // Set the score text.
         guiText.text = "Score: " + score;
 
         // If the score has changed...
         if(previousScore != score)
             // ... play a taunt.
             playerControl.StartCoroutine(playerControl.Taunt());
 
         // Set the previous score to this frame's score.
     
         previousScore = score;
         if(score == 100){
             AudioSource.PlayClipAtPoint(AmerFX, new Vector3(5, 1, 2));        
             Destroy(Amer,5);
 
         }
 
 }
 }
avatar image AndyMartin458 · Nov 15, 2013 at 10:55 PM 0
Share

@Amer_ALhwifi I didn't realize that you were using a 3D audio source. So the problem had to do with the time it took the audio to travel to your player?

avatar image BadSeedProductions · Nov 10, 2015 at 10:15 PM 0
Share

I am trying to load an .ogg vorbis file with playOneShot and it is taking about a second just to play a quick preloaded 2kb sound... Is this normal? Is there a way around this other than using .wav?

avatar image AndyMartin458 BadSeedProductions · Nov 10, 2015 at 10:19 PM 0
Share

That is normal. You'll need to use an uncompressed format.

avatar image BadSeedProductions AndyMartin458 · Nov 14, 2015 at 12:15 AM 0
Share

In my case it turned out to be 'invoke' that was doing the lag. Now my sounds play just fine.

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

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

Related Questions

Lag/jerkiness (as opposed to low framerate) in a Rhythm game 2 Answers

AudioClip huge lag on some android devices 0 Answers

Sound Cracks or Lags on ZTE Blade? 0 Answers

Music Choppy and Weird 0 Answers

Audio Lag Between Multiple Listeners 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