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
I’ve tried this way :
public void Show()
{
meshRenderer.enabled = true;
meshRenderer.material.color = new Color(0, 255, 0);
}
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
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
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;
}
}
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…
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.