返回属于 MovieTexture 的 AudioClip。
请注意,这是一个特殊的 AudioClip,它将始终播放与电影同步的音频。
如果您在 Editor 中将电影的 audioClip 附加到一个源,则会在播放电影时自动开始播放该音频。
否则,您必须在电影开始时手动启动它。
该剪辑只能附加到一个 AudioSource。
See Also: Play, WWW.movie.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(GUITexture))]
[RequireComponent(typeof(AudioSource))]
public class ExampleClass : MonoBehaviour
{
public string url = "http://www.unity3d.com/Movie/sample.ogg";
IEnumerator Start()
{
WWW www = new WWW(url);
MovieTexture movieTexture = www.movie;
while (!movieTexture.isReadyToPlay)
{
yield return null;
}
GUITexture gt = GetComponent<GUITexture>();
gt.texture = movieTexture;
transform.localScale = new Vector3(0, 0, 0);
transform.position = new Vector3(0.5F, 0.5F, 0);
Rect inset = gt.pixelInset;
inset.xMin = -movieTexture.width / 2;
inset.xMax = movieTexture.width / 2;
inset.yMin = -movieTexture.height / 2;
inset.yMax = movieTexture.height / 2;
gt.pixelInset = inset;
AudioSource aud = GetComponent<AudioSource>();
aud.clip = movieTexture.audioClip;
movieTexture.Play();
aud.Play();
}
}