- Home /
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;
}
}
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.
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.
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?
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.
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.
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
Follow this Question
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