I have a script which is meant to change the material on a non-static object, but after it failing, and more testing on other objects, I cannot get it working at all on anything, yet I cannot see any problems with the code, can anyone see what I am doing wrong?
I call MaterialIndex with an arg of 0, then Material with the new material, then ChangeMaterial with the object in question, and nothing changes, but they are being called (confirmed via Debug.Log).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControlMaterials : MonoBehaviour
{
public int materialIndex;
public Material material;
public void MaterialIndex(int value)
{
materialIndex = value;
}
public void Material(Material value)
{
material = value;
}
public void ChangeMaterial(GameObject target)
{
target.GetComponent<MeshRenderer>().materials[materialIndex] = material;
}
}