Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zachypin · Jun 28, 2011 at 04:12 PM · texturevideo

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zachypin · Jun 28, 2011 at 04:33 PM 0
Share

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

avatar image Chris D · Jun 28, 2011 at 04:39 PM 0
Share

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

avatar image zachypin · Jun 28, 2011 at 04:47 PM 0
Share

worked perfectly. thanks :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges