All colors are returning the same value of (127, 127, 127, 255),I can't compare colors because all materials RGBA values are (127, 127, 127, 255)
Hi. I have been trying to check if two colors are equal with this code
private void OnCollisionEnter(Collision collision) {
Color currentColor = GetComponent<Renderer>().material.color;
Color colColor;
colColor.r = collision.gameObject.GetComponent<Renderer>().material.color.r;
colColor.g = collision.gameObject.GetComponent<Renderer>().material.color.g;
colColor.b = collision.gameObject.GetComponent<Renderer>().material.color.b;
colColor.a = collision.gameObject.GetComponent<Renderer>().material.color.a;
if (currentColor.Equals(colColor))
{
Debug.Log("The colors Matched");
Debug.Log("The rockets colour is" + currentColor);
Debug.Log("object you hit has the colour" + colColor);
GetComponent<Renderer>().material.color = Color.red;
}
else
{
Debug.Log("The colors did not match!");
}
}
As you can see, I did some debugs to return the values of currentColor and colColor and the values came out as RGBA(0.500, 0.500, 0.500, 1.000) on both of them.
Both the objects producing these values in debug have different materials with the same RGB values but different A values.
Would anyone be able to help me with fixing this issue?,Hi. I have been trying to check if two colors are equal with this code
private void OnCollisionEnter(Collision collision) {
Color currentColor = GetComponent<Renderer>().material.color;
Color colColor;
colColor.r = collision.gameObject.GetComponent<Renderer>().material.color.r;
colColor.g = collision.gameObject.GetComponent<Renderer>().material.color.g;
colColor.b = collision.gameObject.GetComponent<Renderer>().material.color.b;
colColor.a = collision.gameObject.GetComponent<Renderer>().material.color.a;
if (currentColor.Equals(colColor))
{
Debug.Log("The colors Matched");
Debug.Log("The rockets colour is" + currentColor);
Debug.Log("object you hit has the colour" + colColor);
GetComponent<Renderer>().material.color = Color.red;
}
else
{
Debug.Log("The colors did not match!");
}
}
As you can see, I did some debugs to return the values of currentColor and colColor and the values came out as RGBA(0.500, 0.500, 0.500, 1.000) on both of them.
Both the objects producing these values in debug have different materials with the same RGB values but different A values.
Would anyone be able to help me with fixing this issue?
Your answer
Follow this Question
Related Questions
Change color for disabled button 1 Answer
How to alter Right/Top Value from RectTransform 0 Answers
button function on unity5 1 Answer
Delete object with key within Trigger 1 Answer
Plane character selector unity problem 0 Answers