Change Material Parameters Value??
Hello
So I have the script, where is two material - first is the main and the second in that script is swithing to That works fine for me But one thing i dont know hot to realize. That is how to change my propetries parameter of material by this script So I need to create a loop where is the _Threshold propertie will be going from 0 to 1 and back.
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;
}
}
}
The only thing this is doing is just showing the value of _Treshold not changing it. Help me please.
Your answer
Follow this Question
Related Questions
! Change Material Value ! 1 Answer
Custom Shader IOS Build 0 Answers
Order of elements in array going back to default after being set in different order 1 Answer
Shader makes other objects transparent aswell,Shader Makes everything transparent 0 Answers
Get() and Set() values of a gridArray from another scipt 0 Answers