You just create a script and put in the scene this file have for parts, follow
comment p1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
[InitializeOnLoad]
public class EditorStartup
{
static EditorStartup()
{
// PART 1. Hi
Debug.Log(" ------------ Wellcome to Scrip to change multiple objects
------------");
// PART 2. WRITE YOUR MATEARIAL instead "Roof AI" your material,
// if it's pink chack that yor material exits in Assets\Resources\
YourMaterial.mat
// if not xist creat these folder and copy/past here your material
Material newMat = Resources.Load("Roof AI", typeof(Material)) as
Material;
// PART 3. WRITE YOUR GAME OBJECT instead "81_31_10"
GameObject obj = GameObject.Find("981_31_10");
MeshRenderer[] meshs =
obj.GetComponentsInChildren<MeshRenderer>();
Debug.Log("------------ 2. Model loaded!");
// PART 4. Assignement errors
foreach (MeshRenderer mesh in meshs)
if (newMat != null)
{
mesh.material = newMat;
}
else
{
Debug.LogError(" ****************** Material not found!");
}
Debug.Log("------------ 3. Material is assigned !");
}
}
public class AssignMaterialSame : MonoBehaviour
{
void Start()
{
}
void Update()
{
}
}
CharacterController characterController;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
#region Handles Movment
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runSpeed : walkSpeed) *
Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runSpeed : walkSpeed) *
Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
#endregion
#region Handles Jumping
if (Input.GetButton("Jump") && canMove &&
characterController.isGrounded)
{
moveDirection.y = jumpPower;
}
else
{
moveDirection.y = movementDirectionY;
}
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
#endregion
#region Handles Rotation
characterController.Move(moveDirection * Time.deltaTime);
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX,
0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") *
lookSpeed, 0);
}
#endregion
}
}
It’s full code, I hope it could help you to assign the same material fo many
onjects in Unity