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 invokeCodePudding user response:
When I was in loading the sound is out of question, can you help me, please look at themPublic AudioSource music;
Public AudioClip win;
Private void Awake ()
{
Music=gameObject. GetComponent
Win=Resources. Load
}
Audioclip not to audiosource, why ah
CodePudding user response:
Well, solve, a reconfiguration of the music file path can be dynamically loadedCodePudding user response:
Write the timer, with ctrip WaitingForSecond, with DoTween SetDelay