I wrote this script so that I wouldn’t have to change each material manually, but so that the script would do the work for me.
However it’s not working. And yes, I have the shader assigned in the inspector.
using UnityEngine;
using System.Collections;
public class ToonMaterialScript : MonoBehaviour {
// Array to store all the GameObjects in the scene
GameObject[] AllGameObjects;
// Shader assigned in the inspector
public Shader Shader;
// Use this for initialization
void Start () {
// Find All GameObjects
AllGameObjects = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[];
// Loop through all GameObjects
foreach (GameObject go in AllGameObjects) {
// If the Gameobject has a material
if (go.GetComponent<Material>()) {
// Get the material of the gameobject
Material mat = go.GetComponent<Material> ();
// Set the shader of the material of the gameobject
mat.shader = Shader;
}
}
}
}