- Home /
Switch texture script malfunction
So I currently have a video saved in my projects folder. I have this video play onto a plane using the following code:
function OnMouseDown ()
{
renderer.material.mainTexture.Play();//NOTE TWO
}
This works fine and will play on click.
I want to have a texture on the plane before it's clicked, texture could look like a "play" button. The code I have for this is:
var url = "http://icons.iconarchive.com/icons/deleket/button/256/Button-Play-icon.png";
function Start()
{
var www : WWW = new WWW (url);
yield www;
renderer.material.mainTexture = www.texture;//NOTE ONE
}
On start the texture I want to have on the plane is there and that's fine, but if I click the plane I get an error.
I know that my error is happening because of the two lines I've commented. The line marked "NOTE ONE" is changing what 'mainTexture' refrences, and it now references a 2d image. So when it gets to "NOTE TWO" the code is trying to 'Play()' a 2d image which can't work.
My question, how do I reference the image at "NOTE ONE" so that it isn't changing mainTexture, but will still show the image as its texture?
Answer by Chris D · Jun 28, 2011 at 04:27 PM
Couldn't you just switch the textures first?
function OnMouseDown ()
{
renderer.material.mainTexture = **yourMovieTexture**;
renderer.material.mainTexture.Play();//NOTE TWO
}
Because otherwise it doesn't look like you're changing your texture to your movie at all...So, in start, you're assigning the texture to use until the mouseDown, then you're swapping and playing.
I could, but I don't know how to reference the video in the project folder. $$anonymous$$aybe this picture of my inspector will help? It has the video name in it, "big buck bunny". http://tinypic.com/r/ric2eq/7
Something like:
var the$$anonymous$$ovieTexture : $$anonymous$$ovieTexture;
which you can then drag and drop the reference onto when the script is selected in the project folder.
Then,
function On$$anonymous$$ouseDown ()
{
renderer.material.mainTexture = the$$anonymous$$ovieTexture;
renderer.material.mainTexture.Play();//NOTE TWO
}
That should work, I think. I haven't used movies before, but $$anonymous$$ovieTexture inherits from texture, so...give it a shot, I say :D
Your answer
Follow this Question
Related Questions
Video Texture Loop on TV 0 Answers
How to scroll a sprite? 0 Answers
Replay Video Texture 0 Answers
new Color() not working properly? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers