about how the code dynamically modifies the Sky box in Unity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.