123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlaySounds : MonoBehaviour
- {
- private AudioSource sound;
- public string soundName;
- private float isDestroyTimer;
- void Start()
- {
- // isLoopSound = false;
- sound = this.GetComponent<AudioSource>();
-
- PlaySound();
-
- }
- void Update()
- {
-
- //isDestroyTimer -= Time.deltaTime;
- //if (isDestroyTimer <= 0)
- //{
- // //Destroy(this.gameObject);
- //}
-
- }
- // Update is called once per frame
- public void PlaySound()
- {
- if (sound != null)
- {
- sound.clip = (AudioClip)Resources.Load(soundName, typeof(AudioClip));//调用Resources方法加载AudioClip资源
- sound.Play();
- // isDestroyTimer = sound.clip.length;
- }
- }
- }
|