- Home /
Question by
RealCool_Guy · Aug 05, 2019 at 12:42 AM ·
scripting problemmaterialinstancetilingmaterial renderer
How to change material property of an instance through script
I have code that has recently been broken. I have an object with a material. Once this object is touched by another object it "activates" and starts to glow. I achieved this by having an emission map and scaling it to (1,0) once it becomes activated. See pics below.
Glowing
Not glowing
Originally I used the following code to change the value of the tiling
private void Unlock(DoorKeyStateController controller)
{
//Debug.Log("fucking light up");
material = controller.transform.GetComponent<Renderer>().material; //Get material of the Doorkey attached to the controller
if(material.mainTextureScale != new Vector2(1, 0))
{
material.mainTextureScale = new Vector2(1, 0);
Debug.Log("fucking light up");
}
else { }
...
}
However now when I run the game, the instance of the objects material does not change even though the object is "activated", and my debugs are showing the material property has changed to the vector I assigned. I check the object materials Tiling during runtime and it still shows as (0,0).
Any help would be appreciated
glowing.jpg
(369.2 kB)
unglow.jpg
(262.1 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612210009im_/https://answers.unity.com/themes/thub/images/avi.jpg)