Hide/Show material

Hi guys,
How can I do to pass from “material1” to “material2” when I press a key?

I tried with this script, but this give me an error (the name “gameobject” does not exist in the current context)

Someone can help me? thank you!

using UnityEngine;
using System.Collections;
 
public class Luci4 : MonoBehaviour {
 
    public Material material1;
    public Material material2;
 
 
    void Update () {
 
       if (Input.GetKey(KeyCode.Alpha4))
         gameobject.renderer.material = material2;
 
       if (Input.GetKey(KeyCode.Alpha4))
         gameobjet.renderer.material = material1;
    }
 
}

Have you got renderer attached to your gameObject? Do you initialize your materials variables in the inspector? Is the script attached to any gameObject? Is the script called “Luci4”? If no, please change the name of it.

The variable is named gameObject with an upper case O. You have written it incorrectly on line 13 and 16.