音频拖动条

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ZMusicControl : MonoBehaviour, IDragHandler
{
public Slider slider;

public ZToPlayVideo toPlayVideo;

public Sprite[] sprites;

public Image imageMusic;

#region 音频控制

public void MusicBut()
{

if (slider.gameObject.activeSelf == false)
{
slider.gameObject.SetActive(true);

slider.value = toPlayVideo.audioSource.volume;
}
else
{
slider.gameObject.SetActive(false);
}
}
void IDragHandler.OnDrag(PointerEventData eventData)
{
ValuaControl();
}


private void ValuaControl()
{
toPlayVideo.audioSource.volume = slider.value;

if (slider .value != 0)
{
imageMusic.sprite = sprites[1];
}
else
{
imageMusic.sprite = sprites[0];
}
}

#endregion

}

你可能感兴趣的:(音频拖动条)