- Home /
Object Click launching Movie on GUI Texture
I have different clickable objects in my scene and would like to show a short movie (stored online, accessed via url) on a full screen GUI texture after the object was clicked. Upon clip end or a second click, the GUI should disappear and the camera returning to show the scene.
I used the PlayVideoFit script and put it on the main camera, then attempted to call its LaunchFunction from my CallScriptOnClick script attached to the clickable object. Despite searching the forums I have not found a solution that makes this work and would be very happy to get some help, a hint, or suggestion how this could be done in another way.
// Created by DimasTheDriver in 19/Apr/2011 //
// Available at: http://www.41post.com/?p=3687 //
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (GUITexture))]
[RequireComponent (typeof (AudioSource))]
public class PlayVideoFit : MonoBehaviour
{
//the GUI texture
public GUITexture videoGUItex;
//the Movie texture
public MovieTexture mTex;
//the AudioSource
public AudioSource movieAS;
//the movie name inside the resources folder
public string movieName;
void Awake()
{
//get the attached GUITexture
videoGUItex = this.GetComponent<GUITexture>();
//get the attached AudioSource
movieAS = this.GetComponent<AudioSource>();
//load the movie texture from the resources folder
mTex = (MovieTexture)Resources.Load(movieName);
//set the AudioSource clip to be the same as the movie texture audio clip
movieAS.clip = mTex.audioClip;
//fullscreen with vertical borders
float newWidth = -(Screen.width-(Screen.height*(mTex.width/(float)mTex.height)));
float xOffset = (Screen.width - newWidth)/2;
videoGUItex.pixelInset = new Rect(xOffset, -Screen.height/2,newWidth,0);
}
//On Script Start
public void LaunchFunction ()
{
//set the videoGUItex.texture to be the same as mTex
videoGUItex.texture = mTex;
//Plays the movie
mTex.Play();
//plays the audio from the movie
movieAS.Play();
}
}
Combined with the CallScriptOnClick, which is added to the clickable object.
using UnityEngine;
using System.Collections;
public class CallScriptOnClick : MonoBehaviour
{
/* reference to the PlayVideoFit script */
public PlayVideoFit Menu;
private PlayVideoFit myPlayVideoFit;
/* attempt of calling LaunchFunction in PlayVideoFit script */
void OnMouseDown ()
{
Debug.Log ("Launch Video");
myPlayVideoFit = new PlayVideoFit ();
myPlayVideoFit.LaunchFunction ();
}
}
On your clicking script I don't think your accessing your playVideoFit script properly. Are you getting any errors when you run it?
Your answer
Follow this Question
Related Questions
editable 3d text? 2 Answers
Clickable sphere? 1 Answer
Clicking problem 0 Answers
Best way to import movies into Unity (for the Movie Texture) 3 Answers
IphoneUtils.PlayMovie for Android 1 Answer