返回介绍

MovieTexture.audioClip 音频剪辑

发布于 2019-12-18 15:38:04 字数 3746 浏览 963 评论 0 收藏 0

JavaScript => public var audioClip: AudioClip;
C# => public AudioClip audioClip;

Description 描述

Returns the AudioClip belonging to the MovieTexture.

返回MovieTexture上的音频剪辑。

Note that this is a special AudioClip which will always play its audio synchronized to the movie. If you attach a Movie's audioClip to a source in the editor, it will start playing automatically when the movie is playing, Otherwise you'll have to start it manually when you start the movie. The clip can only be attached to one single AudioSource.

注意这是一个特定的AudioClip它总是与影片同步播放音频。在编辑器中如果你将影片的audioClip附加到一个音频源上,它将在电影播放的时候自动开始播放,否则你必须手动开始它,该剪辑只能被附加到一个AudioSource。

See Also: Play, WWW.movie.

JavaScript:

#pragma strict
@RequireComponent(GUITexture)
@RequireComponent(AudioSource)
public var url: String = "http://www.unity3d.com/webplayers/Movie/sample.ogg";
function Start() {
	var www: WWW = new WWW(url);
	var movieTexture: MovieTexture = www.movie;
	while ( !movieTexture.isReadyToPlay ) {
		null}
	var gt: GUITexture = GetComponent.<GUITexture>();
	gt.texture = movieTexture;
	transform.localScale = new Vector3(0, 0, 0);
	transform.position = new Vector3(0.5F, 0.5F, 0);
	var inset: Rect = 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;
	var aud: AudioSource = GetComponent.<AudioSource>();
	aud.clip = movieTexture.audioClip;
	movieTexture.Play();
	aud.Play();
}

C#:

using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(GUITexture))]
[RequireComponent(typeof(AudioSource))]
public class ExampleClass : MonoBehaviour {
    public string url = "http://www.unity3d.com/webplayers/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();
    }
}

MovieTexture

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文