I want to change the transparency or visibility (alpha) with a UI button

Hi, I am trying to enable an UI Button, but I cant…I want to enable my script with the function (On Click)
adding the Update function. But it doesn’t work.

Basically I want to change the transparency or visibility (alpha) with this button

Please any advice is more than welcome.

private var a : float = 1; // alpha starts at 1
var fadeSpeed : float = 2;
private var Green : b!oolean = true;
function Update(){
    if(Green == true){
        GetComponent.<UI.Text>().material.color.a = Mathf.Lerp(GetComponent.<UI.Text>().material.color.a, 1, Time.deltaTime * fadeSpeed);


        GetComponent.<UI.Text>().material.color.a = Mathf.Lerp(GetComponent.<UI.Text>().material.color.a, 0, Time.deltaTime * fadeSpeed);

OnClick() only works with a function you created yourself.

Make a new function called ChangeAlpha() or soemthing and copy the contents in Update() into it.

function ChangeAlpha(){
    // if(Green == true){...... blah blah blah blah

Then you’ll see the option to call it in the editor menu.

On a side note, you don’t need to write “Green == true”. You just need to write “Green”

if (Green){