- Home /
Changing material on an object multiple times
Hi all,
My current project revolves around a light / dark theme, where dark tiles spread from the outside of a grid towards the center. I'm having trouble with setting different materials to the tile objects. The following code is on the tile prefab;
void Awake(){
this.gameObject.renderer.material = this.lightTex;
}
The following is called from a grid manager which tells the tile to turn to the dark material. This works for this purpose.
public void changeDark(bool turnDark){
if(turnDark == true){
if(this.gameObject.renderer.material = this.lightTex){
isLight = false;
isDark = true;
this.gameObject.renderer.material = this.dark;
}
The following is called from the player which is using the player position to create a temporary list of targets and then sending a message to each of the targets to call this.
public void TargettedTile(){
if(this.gameObject.renderer.material = this.dark){
this.gameObject.renderer.material = this.lightTex;
gameObject.renderer.
Debug.Log ("Was Dark now light" + gameObject.renderer.material.name);
}
}
At the moment the tiles will turn black but will not turn back to light, any ideas?
Thanks
Renoclaf
Your answer
![](https://koobas.hobune.stream/wayback/20220613102343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Change skybox color via script? 0 Answers
Setting texture for a transparent material in c# 0 Answers
Skinned Mesh Renderer - Adding/Removing Materials via C# 0 Answers