Search Unity

How to assign different textures to one mesh?

Discussion in 'Scripting' started by Roldo, Jul 7, 2020.

  1. Roldo

    Roldo

    Joined:
    Oct 25, 2014
    Posts:
    41
    I am generating a mesh at runtime(background made out of quad tiles) and i would want to assign different tile textures to the background. Creating separate game objects for each mesh is not an option as having ~5000 tiles as game objects would not work well. How would i do it?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Different Textures go on Materials.

    If you need different Textures on a Mesh, you need to use different Materials.

    In order to use different Materials your Mesh must have submeshes.

    Each submesh corresponds to a material.

    I have a cool procedural geometry pack I fiddle with from time to time called MakeGeo.

    EDIT: I just threw a multi-material example in there. Look in folder :

    makegeo/Assets/makemultisubmeshquad


    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
    Last edited: Jul 7, 2020
    Zer0Cool likes this.
  3. Zer0Cool

    Zer0Cool

    Joined:
    Oct 24, 2014
    Posts:
    203
    You only need one material here, but you have to set UVs fitting to the generated mesh. Each quad would have its own UV segment on this UV. The texture of the material then is a texture atlas for these quads and would look similar like this:
     
    Last edited: Jul 7, 2020