Caraudio.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Caraudio : MonoBehaviour
  5. {
  6. // Start is called before the first frame update
  7. public float timelenth;
  8. public float timelenth2;
  9. public AudioClip []Music;
  10. void Start()
  11. {
  12. }
  13. public void OnEnable()
  14. {
  15. StartCoroutine(playmusic());
  16. StartCoroutine(playmusichoner());
  17. //Invoke("playmusic", timelenth);
  18. //Invoke("playmusichoner", timelenth2);
  19. }
  20. public IEnumerator playmusic()
  21. {
  22. yield return new WaitForSeconds(11f);
  23. this.gameObject.GetComponent<AudioSource>().clip=Music[0];
  24. this.gameObject.GetComponent<AudioSource>().Play();
  25. }
  26. public IEnumerator playmusichoner()
  27. {
  28. yield return new WaitForSeconds(28f);
  29. this.gameObject.GetComponent<AudioSource>().clip = Music[1];
  30. this.gameObject.GetComponent<AudioSource>().Play();
  31. }
  32. // Update is called once per frame
  33. void Update()
  34. {
  35. }
  36. }