Question by
JoelLeCabbage · Jun 01, 2020 at 07:58 AM ·
c#3dcolor
All colors values are RGBA(127, 127, 127, 255) and I can't fix it
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?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612235806im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why that panel is Invisible?? 0 Answers
[Problem] Change 3DText color with C# script 1 Answer
Dropdown menu: how to make colour change across multiple scenes 0 Answers
Help with grabbing object code 1 Answer
Can not change isTrigger to true 1 Answer