! Change Material Value !

I have the script, where i changing the meterial on child objects. And I need to change the value of the material “Threshold” parametr to be like looping from 0 to 1 and backwords.
Please try to help in this one
Right now its just getting the value of threshold, not changing it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MatSwitch : MonoBehaviour {

    public Material mainMat;
    public Material newMat;
    public Renderer childrens;

    public Shader invert;

    public float min = 0.0f;
    public float max = 1.0f;

    static float t = 0.0f;

    public float thres;

    public bool isMatNew;

    void Start()
    {
        isMatNew = false;

        thres = newMat.GetFloat("_Threshold");

    }

        void Update () {
        Renderer[] childrens;
        childrens = GetComponentsInChildren<Renderer> ();



        if (isMatNew == true) {
            
            thres = Mathf.Lerp (min, max, t);
            t += 0.5f * Time.deltaTime;

            foreach (Renderer rend in childrens) {
                var mats = new Material[rend.materials.Length];
                for (var j = 0; j < rend.materials.Length; j++) {
                    mats [j] = newMat;
                }
                rend.materials = mats;
            }
        }
        if (isMatNew == false) 
        {
            foreach (Renderer rend in childrens) {
                var mainMats = new Material[rend.materials.Length];
                for (var k = 0; k < rend.materials.Length; k++) {
                    mainMats [k] = mainMat;
                }
                rend.materials = mainMats;
            }
        }

        if (t > 1.0f) 
        {
            float temp = max;
            max = min;
            min = max;
            t = 0.0f;
        }
    }
}

You forgot to apply your value after changing it

newMat.SetFloat("_Threshold", thres); 

Take a look here: Unity - Scripting API: Mathf.PingPong

Does exactly what you want and will simplify your code.