yourHousebreaker
yourHousebreaker

Reputation: 99

how to change the color of the object while keeping the original material in unity

Clicking an object with the mouse changes the color of the clicked object

When you select it again, I am making the color of the clicked object and turning it back to the original color of white.

Simply(change the selected object color)

Material mat = objectManager.ReturnMat(obj);
mat.color=color.white

Originally, if you made a uv map for each object, there was no problem even if you changed the mat.color in duplicate.

This time, an object without a uv map is used separately, so if mat.color is applied, the original color is

For example, in the uv map, the specified color is painted with uv, so it was not strange because it was overlaid even if the color was changed.

Objects without a uv map change color, so the original color is blown away.

I don’t know exactly about the shader or texture material

I ask you a question.

Is there a way to change the color without losing the original color of the object through these?

I don't know how many objects can be clicked, but if you save the material for each click, you can enter about one.

Emission is not naturally that color is overlap orignial color

Upvotes: 1

Views: 2393

Answers (2)

Lotan
Lotan

Reputation: 4283

Following @4RZG4 answer:

If it's a performance issue, you can make a Dictionary<int, Color> of Colors, and every time you change the Color of your object, save it on the list, with the correspondent GameObject ID.

When GameObject uses the saved Color, remove it from the Dictionary. This way you will only have the references of the currently changed Colors, instead of every one that can be potentially changeable.

Upvotes: 2

4RZG4
4RZG4

Reputation: 60

Your post was kind of unclear and I don't quite understand what you want, but I assume that you want to keep the original color of the object after you have changed the color to something else.

Implementing this is fairly easy; Just save the material in the Start function like this:

void Start()
{
    Material Temp = mat;
}

Now the original material is stored in a variable named Temp.

If you want to return mat to its original value, you can do like this:

mat = temp;

Upvotes: 0

Related Questions