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 dibonaj · Jul 19, 2011 at 05:02 PM · javascriptobjectmovie

Attaching a script to a second object ruins everything

Hello again everyone.

I'm having some rough times with this video. It works fine when it is just attached to one object. The second I attach it to a second object everything changes. When I click on the first object the sound will play but the texture will now show up. Same thing happens for the second object. But when I take off the component for the second object everything works beautifully on the first. Is there any reason that simply adding a script to a second object will interfere like that? Script follows:

 var movieClip : MovieTexture;
 var movieTexture : GameObject;
 var audioSound : AudioClip;

 function Start()
 {
     movieTexture.active = false;
 }

 function OnMouseUp()
 {
     movieTexture.active = true;
     movieTexture.renderer.material.mainTexture = movieClip;
     movieClip.Play();
     audio.Play();
 }

 function Update()
 {
     if(audio.isPlaying)
     {
         Debug.Log("Audio is playing");
     }
     
     else
     {
         movieTexture.active = false;
     }
 }
Comment
Add comment · Show 1
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 dibonaj · Jul 19, 2011 at 05:09 PM 0
Share

Other notes: As you can see the script has three variables. I simply attach this script to any object I want to have a video attached to, and a plane pops up in the middle of the screen to play the video. I have that plane as a child of my main camera so it follows me around, disabled if no video (in this case checking by sound), is playing.

Once again. Works fine when just attached to one object. movieTexture, however, does not show up when I attach the script to a second object.

1 Reply

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

Answer by sneftel · Jul 19, 2011 at 05:11 PM

You've got two objects with the same MovieTexture. So when you do movieTexture.active = false, that's inactivating it on both of them.

Comment
Add comment · Show 4 · 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 dibonaj · Jul 19, 2011 at 05:23 PM 0
Share

Alright. Adding a second movieTexture into the world did help. But that seems like it would get pretty inefficient pretty fast. Are there any examples somewhere of a more efficient way?

avatar image sneftel · Jul 19, 2011 at 06:08 PM 0
Share

If you don't $$anonymous$$d all of the objects playing in sync, just call Play() at the beginnning, and enable/disable it on a per-object basis by setting or clearing the texture. If you can't have them in sync, you could try Instantiat()ing the $$anonymous$$ovieTexture in Start() and using the copy. I have doubts that that would work, and it would definitely be a resource hog, but it's worth a try.

avatar image Evil-Dog · Jul 19, 2011 at 06:08 PM 0
Share

it's not unefficient, if you're refering to the same pointer it's gonna behave like it did, it's not an efficiency thing, every progra$$anonymous$$g language with pointers works like that.

avatar image dibonaj · Jul 19, 2011 at 06:12 PM 0
Share

Not inefficient in a program$$anonymous$$g sense. Inefficient in the sense that for every video I want attached to an object I need to create a new movieTexture object.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

creating an object using javascript 1 Answer

Move object to raycast point. 3 Answers

Weapon Pickup and change 2 Answers

Making an item class in Unity. 1 Answer

Collision at which side? 1 Answer


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