Home > other >  How to solve the problem of sound broadcast too slow
How to solve the problem of sound broadcast too slow

Time:09-27

When I click a button to play a sound, then the instance to SetActivate=false, thus leading to broadcast sound didn't come to the disabled, could I set again after 0.5 s execution SetActivate=false

CodePudding user response:

Suggest a short audio clips to the appropriate length for playback, and destroyed directly after playing
///& lt; Summary> 
///music playing method
///& lt;/summary>
///& lt; Param name="name" & gt; Music name & lt;/param>
///& lt; Param name="type" & gt; 1 is a short sound 0 is the background music & lt;/param>
///& lt; Param name="DontDestroy & gt;" If not to delete & lt;/param>
Public void PlayAudio (string name, int type=1, bool DontDestroy=false)
{

//create an empty object
GameObject obj=new GameObject ();
If (DontDestroy)
{
DontDestroyOnLoad (obj);
}
Obj. Transform. SetParent (enclosing the transform);
Obj. Name=name;
//add sound effects to empty object
AudioSource=obj. AddComponent (a);
//load sound
AudioClip au=Resources. Load (" audio/" + name);
//assignment
AudioSource. Clip=au;
//if the Bgm
If (type==0)
{
//if it is a long sound will be added to the List in sound
AudioSourceList. Add (audioSource);
AudioSource. Play ();
}
The else
{
AudioSource. Play ();
//if it is a short sound effects play the destruction of their
StartCoroutine (RemoAudio (obj, audioSource));

}

}
///& lt; Summary>
///destruction of sound
///& lt;/summary>
///& lt; Param name="obj" & gt;
///& lt; Param name="audioClip & gt;"
Private IEnumerator RemoAudio (GameObject obj, AudioSource audioClip)
{
If (audioClip & amp; & Obj)
{
Yield return new WaitForSeconds (audioClip. Clip. Length + 0.3 f);
Destroy (obj);
}
}

CodePudding user response:

Solved, myself SetActivate=false to invoke

CodePudding user response:

When I was in loading the sound is out of question, can you help me, please look at them
Public AudioSource music;
Public AudioClip win;

Private void Awake ()
{
Music=gameObject. GetComponent (a);
Win=Resources. Load (" Audio/win ");
}

Audioclip not to audiosource, why ah

CodePudding user response:

Well, solve, a reconfiguration of the music file path can be dynamically loaded

CodePudding user response:

Write the timer, with ctrip WaitingForSecond, with DoTween SetDelay
  • Related