make a transparent object not transparent

hi, i have code that makes something transparent at the start of the game but i want it to be enabled when i right click
here’s my code to make it transparent:

void Start ()
{
gameObject.GetComponent().enabled = false;
}

here’s my code I am trying to use to make it not transparent anymore:

void Update()
{
    if (Input.GetMouseButtonDown(1))
    {
        gameObject.GetComponent<Renderer>().enabled = true;
    }
}

}

it doesn’t work and i don’t know why, please help if you can

It will not work at all. In the start function you should call gameObject.GetComponent<Renderer>().enabled = false;. Because now you disable the object and make it not detect your mouse input.

We need more info, the code you show should work fine.
enabled only disables components, not the entire gameObject. It will disable a script if that is the component you’re Getting.

Did you deactivate your game object somewhere else, like in the inspector? If so then the scripts attached to it don’t run.

This is invalid code:

void Start () { gameObject.GetComponent().enabled = false; }

GetComponent requires a parameter or a type.

Here’s a simple example of working code:

public SpriteRenderer spriteRenderer;
void Start()
{
	spriteRenderer.enabled = false;
}

void Update()
{
	if (Input.GetMouseButtonDown(1))
	{
		spriteRenderer.enabled = true;
	}
}