The question is answered, right answer was accepted
Problem comparing materials of GameObjects
Hi! I can't seem to find an answer for my problem over the internet so Im writing here. I have two GameObjects, for instance lets say: gameObject and Cube1. I want to check if, after randomization or after player changes their materials, they have the same color, that is, the same Material. So I do something like this:
Color1 = Resources.Load("Materials/cube_color_01", typeof(Material)) as Material;
Color2 = Resources.Load("Materials/cube_color_02", typeof(Material)) as Material;
Cube1 = transform.GetChild(0).gameObject;
//then i run some functions to randomize and assing materials to my gameobjects
//then i check:
if (gameObject.GetComponent<Renderer>().material== Cube1.GetComponent<Renderer>().material)
{
Debug.Log("the colors are the same!!");
}
But it wont work : | I have also tried:
( gameObject.GetComponent<Renderer>().name == Cube1.GetComponent<Renderer>().name )
but it also wont work.
Can anybody please help ? :)
this works: if (gameObject.GetComponent().material.color== Cube1.GetComponent().material.color)
problem solved
Follow this Question
Related Questions
can i apply an ad on a material 1 Answer
Use a Raycast to get the Material from a shared Mesh (ProBuilder Object) 0 Answers
Fade Transition Between Two Texture 0 Answers
set normal map texture to HDRP/Lit Material 1 Answer
Can I use MaterialPropertyBlock to set properties per material instead of per renderer? 0 Answers