Question by
LankyJon · Mar 28, 2018 at 03:41 AM ·
prefabmaterialtransparency
Change transparency of instantiated tiles.
Hey there. I'm trying to change the transparency of the tiles I generate depending upon the value of a float. However, when I run the script, none of the tiles are transparent. Note that the prefab's material is set to Rendering Mode 'Transparent.'
Code snippets below. Any help greatly appreciated. Thanks!
private void GenerateLandscape() {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
map[x, y] = (float)(y + 1) / height;
}
}
}
private void InstantiateTiles() {
GameObject selectedTile;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
selectedTile = testTile;
Color tempcolor = selectedTile.GetComponent<Renderer>().sharedMaterial.color;
tempcolor.a = map[x, y];
selectedTile.GetComponent<Renderer>().sharedMaterial.color = tempcolor;
Instantiate(selectedTile, new Vector3(x, y), Quaternion.identity);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Leaves Transparency 0 Answers
How I can make whole gameobject transparent? 0 Answers
how to change a texture on instantiated prefab? 0 Answers
how to hide objects inside an invisible object? 0 Answers
What caused my material to go white? 3 Answers