- Home /
Multiple random tiled textures in one material
I'm not sure if it is possible, because of how unity tiles textures, but I would like to be able to use three separate textures (for instance tile_regular, tile_dark, tile_light) in a single (or multiple if one isn't possible) material, then (because they are tiles...) tile them over an object, but have the individual tile textures on the object be randomly chosen from the three possibilities. For an idea of how this would look: Tiling in Marble Blast Ultra
I don't want to have individual geometry tiles for each tile, and I also would like not to have to pre-bake the randomized tiles outside of unity. If there is a way to just do it OnStart() that would be awesome. Thanks in advance!
Answer by tw1st3d · Jul 25, 2013 at 09:32 PM
using UnityEngine;
using System.Collections;
using System;
public class RandomTexture : Component
{
public Texture[] possibleTextures = new Texture[10]; // Lets you set up to 10 random textures
void Start()
{
SetRandomTexture();
}
public void SetRandomTexture()
{
renderer.material.mainTexture = possibleTextures[random.Next(possibleTextures.length)];
}
}
Create an array of materials and tell the object to pick one on startup. Apply this to each object.
This would work if each tile was a separate object. However, what I need is a way to tell individual tiles of a material to pick a random texture. This is because one large cube can have a hundred tiles on it, but using that script would only randomly select a particular version of a tile to use for ALL the tiles on the cube. I am fairly sure that this will require a custom shader, but I am not familiar enough with custom shaders to figure out what to do.
That sounds like you'll need to enumerate each segment of your cube and paint a texture onto it. Example
Your answer
Follow this Question
Related Questions
Texture Tiling Stopped Working in Unity 4? 2 Answers
Repeating a texture over an object 2 Answers
Texture tiling based on Object size/scale 4 Answers
Material tiling unique to object 1 Answer
Repeat texture common question 2 Answers