- Home /
Change terrain texture colour
I have two textures for my terrain. As a default I use the green texture. However I want my user to be able to change the settings of the game to make the texture red. I have buttons in place that change a string to either say "Green" or "Red". At the start of my game, the below script is run.
using UnityEngine;
using System.Collections;
public class TerrainTexture : MonoBehaviour {
public Texture green;
public Texture red;
public GameObject mapcheck;
public Terrain terrain;
void Update ()
{
if (mapcheck.GetComponent<Script>().map == "Green")
{
// Switch to Green
}
else if (mapcheck.GetComponent<Script>().map == "Red")
{
// Switch to Red
}
}
}
I have done a lot of research but I had various errors when I tried to put anything at my comments. What can I put in place to change the colour of the terrain? (Essentially switching the first texture to the second or vice versa).
Answer by Edwige · Feb 16, 2021 at 03:29 PM
My answer here might help: https://answers.unity.com/questions/1788470/changing-terrain-tint-color-via-script.html?childToView=1814992#answer-1814992
In your case you should try to modify the terrain instead of the map, your texture on the TerrainLayer should be black and white and you should assign a Color and not a texture.
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Distribute terrain in zones 3 Answers
Can't paint more than 8 textures on terrain 3 Answers
I need help with textures. 2 Answers
2D Terrain 1 Answer