- Home /
Move Texture From Plane To GUI And Back
Hi,
I have several planes moving in straight lines across my scene. Each plane has its assigned texture. What I want to be able to do is, on clicking the plane, the texture is displayed in a screen centered static GUI. On clicking this GUI, the texture is re-displayed on the plane, at whatever point the plane has since moved to.
This is my script, which does about half the job, but fails to consistantly react to clicks at all and, though it will clear the GUI texture, it won't then re-display it as required.
tia for any help.
var url : String;
var baseurl = "www.someurl.com/filename";
var filext = ".ogg";
var num : int;
var thisTex : MovieTexture;
var movTexture : MovieTexture;
var obSpeed : int;
var isGUI : boolean = false;
function zoomToGUI(){
isGUI = true;
while (!movTexture.isReadyToPlay)
yield;
obSpeed = 0;
guiTexture.enabled = true;
guiTexture.texture = movTexture;
transform.Translate(obSpeed * Vector3.up * Time.deltaTime * 2);
transform.localScale = Vector3 (0,0,0);
transform.position = Vector3 (0.5,0.5,0);
guiTexture.pixelInset.xMin = -movTexture.width / 2;
guiTexture.pixelInset.xMax = movTexture.width / 2;
guiTexture.pixelInset.yMin = -movTexture.height / 2;
guiTexture.pixelInset.yMax = movTexture.height / 2;
// Play movie
movTexture.Play();
}
function playVid(){
isGUI = false;
var www = new WWW(url);
renderer.enabled = false;
// Make sure the movie is ready to start before we start playing
movTexture = www.movie;
while (!movTexture.isReadyToPlay)
yield;
obSpeed = 2;
movTexture.loop = true;
renderer.enabled = true;
renderer.material.mainTexture = movTexture;
movTexture.Play();
if(movTexture.isPlaying){
// do nothing
}else{
yield WaitForSeconds(5);
renderer.enabled = false;
}
}
function OnMouseDown(){
if(isGUI == false){
zoomToGUI();
}else{
guiTexture.enabled = false;
playVid();
}
}
function Start () {
url = baseurl + num + filext;
playVid();
// Start download
}
function Update() {
transform.Translate(obSpeed * Vector3.up * Time.deltaTime);
}
@script RequireComponent (GUITexture)
Is your redisplay problem down to the fact that zoo$$anonymous$$g to the GUI sets the local transforms scale to 0,0,0 and nothing sets it back? You might be better off just disabling the renderer on the current component rather than doing that scale if that's the effect you are after.
What kind of collider are you using on the component?
It could well be as you say. This is my first real project, so I am still very much learning about the relationship between GUI elements and GameObjects. The moving planes just use a box collider. I could try destroying the plane when it zooms to the GUI, then instantiating another plane when the GUI element is clicked.
Don't destroy the plane, just turn off then renderer with renderer.enabled = false in ZoomToGUI - then don't change the localScale and let me know what the effect is then...
Your answer
Follow this Question
Related Questions
Make a Button out of a Textured Plane 2 Answers
Make a movie texture rewind (play again) 3 Answers
Movie GUI Texture Alpha? 1 Answer
Creating a 2D game using planes with textures 1 Answer
Problem With GUI Circle Thickness 0 Answers