okay, so i made a sclupture of blocks, but i forgot to put the material to them,there is about 300 + blocks, they are all white, how can i make them all become brown?, i tried selecting them all and then puttin the material onto all but it only gives the material to one of 300 blocks please help?
When you make your next sculpture, make a prefab block and use that. Then you’ll be able to, by just changing the prefab, change the collider, add a script, change/add a material… .
For your case, there’s a good chance that you learned the “right way” to do it and should start over (for example, you can use the snapping tool better, and lots of your early blocks are slightly off.)
But, I guess you could write a small program to GameObject[] GO = GameObject.Find
all blocks, then loop GO*.renderer.material = myMat;
*
You could add a script to each block:
function Start(){
renderer.material.color = Color(0.5,1,1);
}
It sounds like the job for an editor script. Here is a quick one that changes the material for all game objects with the name “Cube”. Place it in the Editor folder. The material you want to change it to must be Resources directory and named ChangeMaterial. You activate it from the Windows menu. You needs may require something different, but here is a simple start:
using UnityEditor;
using UnityEngine;
public class ChangeMaterial : EditorWindow
{
Material mat = (Material)Resources.Load ("ChangeMaterial");
string stName = "Cube";
[MenuItem("Window/ChangeMaterial")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(ChangeMaterial));
}
void OnGUI()
{
if (GUI.Button (new Rect(0,0,200,100), "ChangeMaterial")) {
Object[] argo = GameObject.FindObjectsOfType(typeof(GameObject));
for (var i = 0; i < argo.Length; i++) {
if (((GameObject)argo*).name == stName)*
_ ((GameObject)argo*).renderer.material = mat;_
_ }_
_ }_
_ }_
_}*_