Change the gamobject's material makes the game really slow

In my game at every tap the color of 3 different gameobject changes between vìblack and white. probably the script isn’t good cause it makes the game really slow may you help me?

  public Material materialb;
     public Material materialn;
     public bool colorblack;
     int[] mat;
     public static ColorChanging current;
     void Awake()
     {
         if (current == null)
             current = this;
         else
             return;
     }
     // Start is called before the first frame update
     void Start()
     {
         colorblack= true;
     }
     // Update is called once per frame
     void Update()
     {
         if (!BallMovement.current.gameOver && /*!PauseMenu.current.pause &&*/ MovimentoPalla.current.partito)
             CahangeColor();
     }
     void ChangeColor()
     {
         if (gameObject != null)
         {
             if ((Input.GetMouseButtonDown(0) || Input.touches.Any(x => x.phase == TouchPhase.Began)) && !colorblack)
             {
                 GetComponent<Renderer>().material = materialn;
                 colorblack= true;
             }
             else if ((Input.GetMouseButtonDown(0) || Input.touches.Any(x => x.phase == TouchPhase.Began)) && colorblack)
             {
                 GetComponent<Renderer>().material = materialb;
                 colorblack= false;
             }
         }
     }

Thank you!

There’s a line error at 22: CahangeColor();
Try to cache the component Renderer?

CahangeColor();

it’s only a typing error cause I had to translate the code to make more comprensible for you.

How can I cache the component renderer?

Mi sembra che tu sia italiano quindi ti rispondo così. Per cachare un componente devi semplicemente dichiarare una variabile di tipo rigidbody: private RigidBody rgbd
Poi nel metodo start fare: rgbd = GetComponent()
In questo modo potrai fare tutte le operazione che vuoi sul rigidbody utilizzando rgbd come ad esempio rgbd.AddForce

Ma quale è la relazione tra il rigidbody e il renderer?