Fade Out On Click

Hey Guys,
Trying to design a main menu with a fade out on click feature on the text, the problem seems to be that whenever I click it will fade out by 1 frame, and I have to keep clicking to get it to fade out completely, or hold down the mouse.At the moment the click code is highlighted out so it’s just flashing. Below is the code i’m using, any help would be greatly appreciated.

#pragma strict

var particle : Component;

var colorStart = Color.blue;

var colorEnd = Color.clear;

var duration = 1.0;

function Update () {

// if (Input.GetKey (“mouse 0”))

// {

var lerp = Mathf.PingPong (Time.time, duration) / duration;

renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp);
// }

/*function OnMouseDown ()



This is the way i do on C#:

public float alphaValue = 1.0f;
public bool check = false;

void Update(){
    alphaValue -= Mathf.Clamp01(Time.deltatime/0.5)

void OnGUI(){
GUI.Color = new Color(1,1,1,alphaValue);
if(GUI.Button(new Rect(100,100,100,25), "myButton")){
       check = true;

This will fade out your button, try to make the same way to fade in again.