I’m trying to get an object that will follow a path and change a tiles texture to look like a road on the path it follows. Pathing is fine and I seem to be referencing the correct object on collision and debugging tells me I get to the proper code. However, the textures refuse to change. I can do it manually just fine but for some reason it won’t change at run time.
Here’s my code:
public Texture roadTexture;
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == 3)
{
Debug.Log(other.material);
Debug.Log(other.gameObject.GetComponent<Renderer>().materials[0].mainTexture);
other.gameObject.GetComponent<Renderer>().materials[0].SetTexture("_MainTex", roadTexture);
}
}
the other collider is in layer 3 and both debug logs run and show me I’m referencing the correct material (I also debugged object names and tags to make sure it was referencing the correct object too). Any help would be appreciated.