Search Unity

Automatic Material tiling according to object size

Discussion in 'Editor & General Support' started by luigix, Nov 21, 2010.

  1. luigix

    luigix

    Joined:
    Mar 13, 2010
    Posts:
    15
    So this is the scenario:
    Imagine having something like different sized platform for a 2D game.
    I have n prefabs which are just cubes.

    Each cube has ySize=1 zSize=1 and xSize=n

    So for n=3 I have
    Cube1 Size (x,y,z) = 1,1,1
    Cube2 Size (x,y,z) = 2,1,1
    Cube3 Size (x,y,z) = 3,1,1

    This is the problem:
    My material in order to map correctly the texture, needs to tile differently according to X size of my objects.
    So for now I'm creating a different material for every new object I have.

    Issues
    if I wan to edit the platform material I will have to modify N materials.
    if I have 40 different sizes of the same object I have to create 40 different materials.

    I'd love to have just ONE object and ONE material, with the X tile changing as I change the X size of my object.
    Is that possible?
     
    Last edited: Dec 9, 2010
  2. Paulius-Liekis

    Paulius-Liekis

    Joined:
    Aug 31, 2009
    Posts:
    672
    My first though would be to write a custom shader which map UV based on position of vertices, but maybe there is better approach...
     
  3. luigix

    luigix

    Joined:
    Mar 13, 2010
    Posts:
    15
    Would love to try, but I really have no idea on how to do that. Yet :)