Version: 5.4 beta (switch to 5.3)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MovieTexture.audioClip

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var audioClip: AudioClip;
public AudioClip audioClip;

Description

Returns the AudioClip belonging to the 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.

See Also: Play, WWW.movie.

#pragma strict
@RequireComponent(GUITexture)
@RequireComponent(AudioSource)
public var url: String = "http://www.unity3d.com/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();
}
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(); } }