- Home /
i want to assign different colors to rows or different colors to the brick?
I am Instantiating prefabs to build a wall of bricks using this code.
void Start () {
float z = 2.2f;
float y = 1f;
float x = -12f;
float increment = 2f;
float spacing = 1.3f;
for (y = 1f; y < 3.8f; y++) {
for (x = -14; x < 3.5f; x++) {
Instantiate(brick, new Vector3(x, y, z)*spacing, Quaternion.identity);
}
}
}
I would be very helpful if someone can guide me to proceed to assign different colors to rows or each brick.
There are a huge variety of ways to do this. One option is creating a few different prefabs that have slightly different properties (such as color) and depending on your x, and y values within the nested for loops, instantiate a different brick.
Another way to do it is to get access to the renderer of the game object, then manually set the color on the material, like this:
renderer.material.color = Color.red;
Another option is to not create a brick wall with so many different bricks, but to rather model a brick wall in a modelling program (I recommend Blender) and use that. If you need the wall to be destructable, then you can create a model of the wall, then create a few other 'destructed' models to use, and upon destruction, instantiate a random destructed version.
There are lot's of options, and it depends on things such as your skill level, your requirements, etc...
I know this isn't an answer (hence the comment) but hopefully it steers you in the right direction.
Your answer
Follow this Question
Related Questions
How do i Instantiate a prefab with specific assests included 3 Answers
,Instantiating Prefab in C# 0 Answers
Issue Instantiating prefab in C# 0 Answers
Issue Instantiating prefab in C# 2 Answers
Destroying Objects. 1 Answer