Animating Material, how to set material after animation?
My current goal is to Animate the material of an object to appear like it is flashing. I have created an animation that every 20 frames sets the objects material to "MaterialBlue" or MaterialGreen" (Mesh Renderer.Material in animator). This works and the animations take place as they should. However with the middle mouse click I want to set the material of the object to matRed after the animation and only on the mouse click. Nothing is happening though. I am guessing this is because I am playing "Ani_Off" so the material is being set every frame in the animation to "MaterialBlue". Is there a way to do this better or is there a simple fix i am missing like stopping the animation etc. When debugging I have found the material of the object is being changed to matRed but it does not appear red, so I think it has something to do with me mis-understanding the animator.
I have currently created this:
public Animator ani;
public Animator aniTWO;
public Transform one;
public Transform two;
public Material matRed;
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) //Left Click
{
//Play Animation
Debug.Log("leftClick");
aniTWO.Play("SphereColour");
ani.Play("Ani_Off");
}
if (Input.GetMouseButtonDown(1)) //Left Click
{
//Play Animation
Debug.Log("RightClick");
ani.Play("SphereColour");
aniTWO.Play("Ani_Off");
}
if (Input.GetMouseButtonDown(2))
{
Debug.Log("MiddleClick");
one.GetComponent<Renderer>().material = two.GetComponent<Renderer>().material = matRed;
}
}