system
1
I work on a project to (for simple) change the color of the walls of a house.
For that I prepare a home (for now it is a cube) in which I separate the walls of the rest of the model (in 3DS Max) and I named this group of wall “Mur”.
In Unity, I have my house with the “under subject” => “Mur” but I can not access it to change its texture.
txtrLoader = Resources.Load(“Texture/texture”, typeof(Texture2D)) as Texture2D;
Component sousObject = GetComponent(“Mur”) as Component;
//sousObject.renderer.material.mainTexture = txtrLoader;
//sousObject.renderer.material.SetTexture(“_MainTex”,txtrLoader);
here are the two things I try for now (in comment)
and the error is : “NullReferenceException: Object reference not set to an instance of an object”.
DaveA
2
Loadable resources need to be in or under a folder called Resources within Assets
system
3
txtrLoader = Resources.Load(“Texture/texture”, typeof(Texture2D)) as Texture2D;
Transform sousObject = curModel.transform.FindChild(“Mur”);
sousObject.renderer.material.mainTexture = txtrLoader;
I managed to find the right way, with these three lines, I target the “Mur” and I replace its texture.