RandomMaterial.cs 348 B

12345678910111213141516
  1. using UnityEngine;
  2. using System;
  3. public class RandomMaterial:MonoBehaviour{
  4. public Renderer targetRenderer;
  5. public Material[] materials;
  6. public void Start() {
  7. ChangeMaterial();
  8. }
  9. public void ChangeMaterial(){
  10. targetRenderer.sharedMaterial = materials[UnityEngine.Random.Range(0, materials.Length)];
  11. }
  12. }