Unity3D学习记录——AudioSource2

1.添加播放按钮播放,或者暂停按钮暂停

2.创建空物体,添加GUI Texture组件,添加图片素材


3.编写Play脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Play : MonoBehaviour {

    private AudioSource m_audiosource;
    public AudioClip m_audioclip;

	// Use this for initialization
	void Start () {
        m_audiosource = GameObject.Find("Audio").GetComponent();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnMouseDown() {
        m_audiosource.PlayOneShot(m_audioclip);
    }
}
4.添加Audioclip bg_hlw


5.编写Pause脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pause : MonoBehaviour {

    private AudioSource m_audiosource;
    public AudioClip m_audioclip;

	// Use this for initialization
	void Start () {
        m_audiosource = GameObject.Find("Audio").GetComponent();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnMouseDown() {
        m_audiosource.Pause();
    }
}
6.添加Audioclip bg_hlw


你可能感兴趣的:(Unity3D)