How to write a function that makes the colour change

public class SilverFernScript : MonoBehaviour
{
private void Start()
{

}
void Update()
{

    // Moves the silver fern forward along its z axis 1 unit/second.
    transform.Translate(Vector3.forward * Time.deltaTime);

    // Moves the silver fern upward in world space 1 unit/second.
    transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}

private void OnCollisionEnter(Collision collision)
{

    if (collision.collider.CompareTag("User"))
        
    {

        {

        }

        //private void OnCollisionEnter(Collisison collision)
        //{
        //if (collision.collider.CompareTag == "User")

        void Cyan()
        {
            Renderer rend = GetComponent<Renderer>();
            //changes the colour to cyan
            rend.material.shader = Shader.Find("_Color");
            rend.material.SetColor("_Color", Color.cyan);

            rend.material.shader = Shader.Find("Specular");
            rend.material.SetColor("_SpecColor", Color.cyan);
        }

        void yellow()
        {
            Renderer rend = GetComponent<Renderer>();
            //changes the color to yellow
            rend.material.shader = Shader.Find("_Color");
            rend.material.SetColor("_Color", Color.yellow);

            rend.material.shader = Shader.Find("Specular");
            rend.material.SetColor("_SpecColor", Color.yellow);
        }

        void red()
        {
            Renderer rend = GetComponent<Renderer>();
            //changes the color to red
            rend.material.shader = Shader.Find("Color");
            rend.material.SetColor("_Color", Color.red);

            rend.material.shader = Shader.Find("Specular");
            rend.material.SetColor("_SpecColor", Color.red);
        }
    How can I make a void function to make my color script work? Also, my current script seems to have a lot of errors.

You are defining void functions INSIDE another function, that’s the problem. That script won’t compile, you must declare every void function outside the event function OnCollisionEnter. And inside OnCOllisionEnter you can call those functions like this:

public class SilverFernScript : MonoBehaviour
{
    private void Start()
    {

    }
    void Update()
    {
        // Moves the silver fern forward along its z axis 1 unit/second.
        transform.Translate(Vector3.forward * Time.deltaTime);
        // Moves the silver fern upward in world space 1 unit/second.
        transform.Translate(Vector3.up * Time.deltaTime, Space.World);
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.CompareTag("User"))

        {
            Renderer ren = GetComponent<Renderer>();
            if (ren.material.GetColor("_Color") == Color.cyan)
            {
                yellow();
            }
            else if (ren.material.GetColor("_Color") == Color.yellow)
            {
                red();
            }
            else if (ren.material.GetColor("_Color") == Color.red)
            {
                Cyan();
            }
        }
    }

    void Cyan()
    {
        Renderer rend = GetComponent<Renderer>();
        //changes the colour to cyan
        rend.material.shader = Shader.Find("_Color");
        rend.material.SetColor("_Color", Color.cyan);
        rend.material.shader = Shader.Find("Specular");
        rend.material.SetColor("_SpecColor", Color.cyan);
    }
    void yellow()
    {
        Renderer rend = GetComponent<Renderer>();
        //changes the color to yellow
        rend.material.shader = Shader.Find("_Color");
        rend.material.SetColor("_Color", Color.yellow);
        rend.material.shader = Shader.Find("Specular");
        rend.material.SetColor("_SpecColor", Color.yellow);
    }
    void red()
    {
        Renderer rend = GetComponent<Renderer>();
        //changes the color to red
        rend.material.shader = Shader.Find("Color");
        rend.material.SetColor("_Color", Color.red);
        rend.material.shader = Shader.Find("Specular");
        rend.material.SetColor("_SpecColor", Color.red);
    }
}

// This code will cycle through colors every time this object suffers a collision from User
// Remember to attach this script on the object you want its color to change