Hiya, I have been working on a project recently that will incorporate movies into a Space Style application, it is just to be prototype'd using Unity3D (not in IOS Pro yet as we cannot afford it :P)
Anyway the problem i am having is that when the user reaches a specific Planet, say Saturn, that the application will give the user to watch a Movie about that planet. I was wondering is there a way in which we could do it so that we would not need to make a new script file for every single video. We have an enumerated type for the Planet's but wondering how we could pass that in so that it will manipulate which video is being played.
public class PlayMovieScript : MonoBehaviour {
public Texture buttSun;
public Texture buttStop;
bool playVideo = false;
public MovieTexture movie;
void OnGUI()
{
if(playVideo == true)
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), movie, ScaleMode.StretchToFill, false, 0.0f);
}
PlayMovieFunction();
}
void PlayMovieFunction()
{
if(movie.isPlaying == false && GUI.Button (new Rect (1000, 25, 40, 40), buttSun))
{
playVideo = true;
movie.Play();
audio.Play();
}
else if (movie.isPlaying == true && GUI.Button (new Rect (1000, 25, 40, 40), buttStop))
{
playVideo = false;
movie.Stop();
audio.Stop();
}
}
}
There is probably something simple that I am missing, but we just would like to be able to manipulate which Movie is being passed into these functions to be drawn depending on the planets. We tried passing parameters into OnGUI but that is not allowed.
Is this script on one object that will play all movies, or do you have multiple movie objects, each with its own movie? In the latter case, you just assign the movie to each instance using the Inspector or script.
Mine loads the movies via WWW, so instead of MovieTexture, I expose the URL and set that (per instance in my case, as I have multiple movie items). I made my movie object into Prefab. Anyway to see how to do this, check this: http://unity3d.com/support/documentation/ScriptReference/WWW-movie.html You can see there that the url is given, and that can be passed in from anything, including a GUI item.
@DaveA
Hi this is an old post but im wondering if you could help.
I am trying to change the movieTexture on my Raw Image when I press a button. I have a few buttons and a few videos, Im trying to make it so that if I press button A then video A plays, button B video B plays and so on.
I have the following code which I have added to every button, on the inspector I have given each button a different video to play. But the only video that will play is the one that is originally a movie texture of the raw image (video A) so if I click button A the video plays fine, but if I press button B nothing happens, the movie texture doesn’t change and nothing plays.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VideoController : MonoBehaviour
{
public MovieTexture video;
public void OnMouseDown()
{
GetComponent<Renderer>().material.mainTexture = video as MovieTexture;
if (!video.isPlaying)
{
video.Stop();
}
video.Play();
}
void Update()
{
}
}
Im unsure what the best approach will be, as I need all the videos to play on the same raw image (so that they all appear on the same space of the canvas)
I dont know if adding ids would be helpful, or if piling up different RawImages on top of each other and enabling them when a different button is pressed…but this seems like a really bad unsophisticated approach