There are two ways to dynamically modify the sky box in Unity:
One, for each texture set up the Sky box material ball, need to replace the corresponding material directly to the ball as a sky box, the disadvantage is that the building of a material ball too much
Private void Changeskybox (Material newskybox) { = newskybox; }
Second, only create a Sky box material ball, by modifying the material map CubeMap to dynamically replace, the advantage is no need to create extra material ball
However, you cannot assign a map of type cubemap using the generic Material.maintexture property.
Find a way to modify the Texture of Material by reviewing the unity-scripting API: Material.settexture (string name, Texture value)
We found that the corresponding map location can be obtained by specifying the parameter name. However, it does not indicate what the CubeMap parameter is. It is therefore only possible to view the property of shader.
Select the Created Sky box Material ball, right click Shader Select Edit Shader ..., open the details of the Shader as shown in
In the open shader details we found a row in the properties
The original cubemap name parameter should be filled with "_tex", the name parameter actually refers to the corresponding property attribute in shader.
So the cubemap map of Sky Box can be changed dynamically by the following methods
1 Private void Changeskybox (Texture Texture) 2 {3 RenderSettings.skybox.SetTexture ("_tex", texture); 4 }
about how the code dynamically modifies the Sky box in Unity