This is driving me absolutely batty.
I have the following C# script:
using UnityEngine;
using System.Collections;
public class TextureChanger : MonoBehaviour {
public Material openEyesTexture;
public Material closedEyesTexture;
public GameObject player;
public void CloseEyes()
{
player.renderer.material=closedEyesTexture;
}
public void OpenEyes()
{
player.renderer.material=openEyesTexture;
}
}
This works fine at changing the material of the player, and I can see it changing the the player’s inspector, but it is not changing in the scene. I have the functions “CloseEyes” and “OpenEyes” firing with animation events.
I am pretty sure it is because the player has a child “alpha” and a child “body” that are taking the material from the player and are not updating.
I’ve tried so many different things (and looked at a million forums) to get this to work and have tried accessing the children, but everything I’ve tried throws error messages at me.
Could someone please offer some advise on how to get this to work.
P.S. I’ve also done this by changing the texture of the main material and I get the same result.