Changing material of UI when pressed

Hello, for my VR application I need to change material of the image component of the UI button I used.
I wrote a code to do that but when trying to add it to the gameobject, Unity gives me “script class cannot be found” error.
This script will be executed through an OnClick function in the button component of the same gameobject.

Can anyone help me?
I’m relatively new to Unity, I’m sorry for any obvious errors.

using UnityEngine;
using System.Collections;
using UnityEngine.UIElements;  // dont know if I have to use this or the next one or neither or both
using UnityEngine.UI;

public class ChangeMaterial : MonoBehaviour
{
    public GameObject myObject;
    private Color startmaterial;
    int counter=0;

    void start ()
    {
    }

    public void materialf()
    {
        counter++;
        if (counter%2==1)
        {
           
            startmaterial = myObject.GetComponent<Image>().material.color = Color.green;

        }
        if (counter%2==0)
        {
            myObject.GetComponent<Image>().material.color = startmaterial;
           
        }
    }
}

This usually happens if Unity cannot ‘recognize’ the class. And that usually happens when the class-name is not equal to the filename.
Is your class ‘ChangeMaterial’ in a file ‘ChangeMaterial.cs’?

Yes, I confirm that the names are equal.

See the top answer in this post. Have you tried all these things?

Yes, I did everything from that list. The file name and the class name are the same. In visual studio I cannot find any error, nothing is underlined in red like an error. I tried several times to copy all the code and pasting it in another file (w/ different class name and file name), but nothing.