stop materal instancing
hey unity devs,
Is there a way to edit a materails property from a scrpt without making a new instanec of that materail so I only need to have the script on one object, heres my script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class water4ColorUpdater : MonoBehaviour {
public float blueAdd;
public Color waterColor = new Color(0,0,0,1);
public Color finalColor = new Color(0,0,0,1);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
finalColor.r = (RenderSettings.ambientLight.r * waterColor.r) + (0.1f * waterColor.r);
finalColor.g = (RenderSettings.ambientLight.g * waterColor.g) + (0.1f * waterColor.g);
finalColor.b = (RenderSettings.ambientLight.b * waterColor.b) + (0.1f * waterColor.b);
finalColor.a = 1;
Renderer rend = GetComponent<Renderer>();
rend.material.SetColor("_ReflectionColor", finalColor);
}
}
Comment
Best Answer
Answer by insominx · Jan 06, 2018 at 06:14 PM
sharedMaterial might be what you're after: https://docs.unity3d.com/ScriptReference/Renderer-sharedMaterial.html
@inso$$anonymous$$x that sounds about right, thanks.
Your answer
Follow this Question
Related Questions
Shader displaying with weird colors 1 Answer
Unable to edit grey ,,locked,, Materials 3 Answers
Giving a Material two different colors using a png Mask, 0 Answers
Unity shaders/materials outside unity enviroment,Unity object export with shaders from shadergraph 0 Answers
Slime shader (Fall Guys like material) 0 Answers