Opacity / Transparency?

Hi Everyone,

I’m new to Unity and am trying to convert a project into Unity 3.1. I’m trying to figure out how to trigger a object’s Opacity / Transparency either via script or animation and am having some trouble. My goal here is to have a object disappear and reappear on command; my previous project was in Esperient Creator and this was controlled via action script that either turned the object on or off in the engine, or flip its opacity levels. :face_with_spiral_eyes:

After consulting the Google gods and looking in the forums I’m still scratching my head on this issue. Can anybody show me where I can find how to do this or possibly know of a script that could do this?

Any help is greatly appreciated! :smile:

renderer.material.color.a (using a shader that has transparency), but if you just want to make an object visible/invisible as opposed to fading it out, then use renderer.enabled = true/false instead (doesn’t require any specific shader).

–Eric

you can disable the whole object by using gameObject.active = false or if you still need its updates to run and just want to hide it you can use renderer.enabled = false

Hey Eric!

Thanks for the reply. I’m trying to implement those commands but I’m not having any luck (since I’m not sure where I need to put them); I made them into a test script to see if I can get them working but being new I’m not totally sure if I’m doing this right. Here’s a screenshot of my object with script assigned and its test script:

(In the case the image disappears)

function OnOffTest() {
gameObject.active = false;
}

Just trying to see if I can make this test plane disappear when I press play. I know I’m probably doing this horribly wrong so the help would be greatly appreciated. :smile:

Does your script file contain only your OnOffTest function? Some functions get called automatically by Unity at certain stages of gameplay. Try testing with this added to the file:-

function Update() {
  if (Input.GetMouseButtonDown(0))
    OnOffTest();
}

This should make the GameObject inactive when the mouse button is pressed.

Also, if you just want something to run automatically when you press play, you can put it in a Start() function.

–Eric

Thanks andeee!

After adding the function Update () script, it works now! :smile: Say if I were to reactivate the GameObject, how would I go about doing that? I tried altering the gameObject.active = false; line by adding the object’s name…

gameObject.active "Plane" = true;

…to no avail. :face_with_spiral_eyes: