- Home /
Toggle Visibility
Newbie Question
when I click on one object, I am trying to "turn on" the texture of another a plane called "Plane_1"
function OnMouseUp () { if (GameObject."Plane_1".renderer.enabled == false) { GameObject."Plane_1".renderer.enabled = true; } else if (GameObject."Plane_1".renderer.enabled == true) { GameObject."Plane_1".renderer.enabled = false; }
}
Thanks Be
Does this compile/run? I suspect it doesn't (don't use JS myself) You probably need to create a Transform variable (let's call it target), assign the Plane_1 to it in the Editor and change all these GameObject."Plane_1" to target
@getyour411 Yup = Nope doesn't run. You're right - The problem is in declaring the variable (.js)
var taget : GameObject = Plane_1;
function On$$anonymous$$ouseUp () {
if (target.renderer.enabled == false) {
target.renderer.enabled = true;
}
else if (target.renderer.enabled == true) {
target.renderer.enabled = false;
}
}
@getyour411 B R I L L I A N T !!! Thank you $$anonymous$$ucho!
Hardly smiles just been there/done that. I changed to Answer, please mark if you see this.
Answer by getyour411 · Jan 14, 2014 at 01:38 AM
I don't use JS but I suspect the var dec should be var target : GameObject (and nothing else). Then, look in your Editor at the GameObject this script is attached to and you should see a new property on it that's expecting a GameObject. Drag/drop the Plane_1 object from the hierachy into that