Change tile color

Hello.
I would want to change the Tile color according if it’s available for movement or not.
For that I’ve created a new material called GridMaterial and assigned the Grid Texture you give to the base color of the new GridMaterial created.
After that I assign this gridMaterial to the Quad’s materials in its meshRenderer but after, I dont know how to access to the color by script and change it.
If I change it manually, it work fine but in the script when if I change the meshRenderer Color, it’s all the map which change :grimacing:

I’ve tried this way :

    public void Show()
    {
        meshRenderer.enabled = true;
        meshRenderer.material.color = new Color(0, 255, 0);
    }

but everything turn green :slight_smile:

I understand I must access to the color of the GRidMaterial assigned to my Quad but I don’t see too much how to do that …
Any suggestion?
Thanks.
François

You have to instantiate the material so that it’s treated separately.

In Start(), try adding this:

meshRenderer.material = Instantiate(meshRenderer.sharedMaterial);

Hello Brian,
thanks for your reply.
I’ve had the start sequence as you suggest.
I read on unity scripting it create a clone of my material. so ok.
But it doesn’t look too change anything in the result…
the whole screen is fullgreen :slight_smile:

here is my script:

public class GridSystemVisualSingle : MonoBehaviour
{
    [SerializeField] private MeshRenderer meshRenderer;

    private void Start()
    {
        meshRenderer.material = Instantiate(meshRenderer.sharedMaterial);
    }
    public void Show()
    {
        meshRenderer.enabled = true;
        meshRenderer.material.color = new Color(0, 255, 0);
    }

    public void Hide()
    {
        meshRenderer.enabled = false;
    }

}

Thanks for your help.

I do this in update … but start should would work if you want a static color.

        `meshRenderer.material.SetColor("_BaseColor", mynewfancycolor);`

I think this may be issue, SetColor vs .color.

That’s very strange, are you sure you’re changing the meshRenderer for that tile? You’re sure you’re not modifying the meshRenderer for some Image Effect?
Changing the color of the tile definitely shouldn’t be making the whole screen green (unless for some reason you added a tile object right in front of the camera)
Pause the game while it’s running, what do you see in scene view? Do you see a giant quad? Is the scene view also green?
Maybe it’s an issue with your graphics card, maybe try updating your drivers, very strange.

Hello Mister Monkey.
Thanks for your reply.
When I put my code line to change the color, it’s like if there is a uggly glow centered in the unit. I move with it…
I work in a grid of 15x15 so 225 tiles.
When I launch the game, there are 225 tiles created.
No more…

It 's like some thing multiplied the green color tile…
Don’t undestand why.
I can share you my project if you want.
Thanks for your courses.
Schusss

François

Oh now I see the issue!

The values in the Color struct are normalized, meaning between 0 and 1 Unity - Scripting API: Color
If you want full green then you should be using (0, 1, 0) not (0, 255, 0)

What you are seeing is basically a green color that is pretty much as bright as the sun which is why it overpowers everything, set it to just (0, 1, 0) or use the constant Color.green and it will look a normal green.

2 Likes

Brightness (play of word :slight_smile: )
you are right.
With normalized values it works perfectcly :slight_smile:

Next step create a kind of offset tiles in red to say forbiden destination.
Like in fire emblem :wink:

Thanks every one.
Have a nice day.
François

I definitely misunderstood the original question… I was thinking that all tiles materials were turning green, and I was scratching my head as to why.

hello Brian,
no problem. Thanks to have spend some time for me :slight_smile:
Have a nice day.
François

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms