How to hide/show terrain and other gameObjects during run-time (by C# code)?
I want to show/hide terrain and gameObjects in a fade-in/out style
Asked
Active
Viewed 284 times
-1

Cœur
- 37,241
- 25
- 195
- 267

Al-Hanash Moataz
- 385
- 4
- 14
-
1To get a "fade-in/out" style you will need a shader. WIll you tell us why you want to do this, this may help giving you an appropriate answer. – AntiHeadshot Dec 22 '15 at 07:35
-
What material/shader are you using? Standard? – Hamza Hasan Dec 22 '15 at 07:47
2 Answers
1
The Terrain script uses a built-in shader by default. This one is not accessible nor modifiable.
Material mat = terrain.materialTemplate;
Debug.Log(mat==null); // True
Assigning a custom shader is limited to the Nature shader and none offers the use of Color. It seems in general that the terrain ignores the color of a shader.
Material mat = terrain.materialTemplate;
Color c = mat.color;
c.a = 0.5f;
mat.color = c;
This will show the modification in the shader color but no effect on the terrain itself.
As a result you would have to create your own shader, like this one http://wiki.unity3d.com/index.php/TerrainTransparency

Everts
- 10,408
- 2
- 34
- 45
0
public class ChangeAlpha : MonoBehaviour {
public Renderer Renderer;
private Material _material;
// Use this for initialization
void Start () {
_material = Renderer.material;
StartCoroutine("ChangeAlphaSlowly");
}
private IEnumerator ChangeAlphaSlowly()
{
var increaseAmount = 0f;
var _color = new Color(0, 0, 1, 0);
for (int i = 0; i < 10; i++)//ten step
{
increaseAmount += 0.1f;
_material.color = new Color(0, 0, 1, increaseAmount);
yield return new WaitForSeconds(0.1f);
}
}
}

Halil Cosgun
- 427
- 3
- 10
- 24
-
-
You can use canvas and canvas group's alpha property for show/hide effect on camera. If I want to show and hide my all gameobjects on the scene with fade in/out stlye, I use this way. Sorry, I tried to help you. – Halil Cosgun Dec 22 '15 at 10:00