using UnityEngine;
using System.Collections;
public class ChangeMaterial : MonoBehaviour
{
private Renderer rend;
private Shader differentShader;
public int[,] materials = new int [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
void Start ()
{
differentShader = Shader.Find ("Toon/Lit Outline");
rend = GetComponent<Renderer> ();
rend.enabled = true;
rend.sharedMaterial = materials[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
for (int i = 0; i < materials.Length; i++)
{
rend.sharedMaterial.shader = differentShader;
}
}
}
I created this “for” loop earlier to change the Shader of all 30 elements (which are materials) at the beginning of the scene. I am using an array as opposed to a list because the indexes will not change.
The error is in line 10. What am I doing wrong?