Question by 
               CasperLIHongKong · Mar 26, 2016 at 07:17 PM · 
                animationscripting problemmaterialchange  
              
 
              How to Change Albedo in Main Maps By Script
I an now writing a C# script for animating the cube texture to display two different images toggling in a constant speed like 0.2s. 
 How can I change the materials of Albedo by C# script? I don't know the component name so I don't know how to get its object. 
 using UnityEngine;
 using System.Collections;
 
 public class TwoImageChangeAnimation : MonoBehaviour {
 
     private GUITexture gui_texture;
     public float changing_rate;
     private float org_changing_rate;
 
     public Material image_01;
     public Material  image_02;
 
     private enum STATE {
         State01, State02
     };
     private STATE currentState;
 
     // Use this for initialization
     void Start () {
         gui_texture = gameObject.GetComponent<GUITexture> ();
         org_changing_rate = changing_rate;
         currentState = STATE.State01;
     }
 
     // Update is called once per frame
     void Update () {
         changing_rate -= Time.deltaTime;
         if (changing_rate < 0) {
             ToggleImage();
             changing_rate = org_changing_rate;
         }
     }
         
     void ToggleImage() {
         switch (currentState) {
         case STATE.State01:
             gui_texture.material = background_02;  // Here should be the codes for changing the material
             currentState =    STATE.State02;
             break;
 
         case STATE.State02:
             gui_texture.material = background_01;  // Here should be the codes for changing the material
             currentState =    STATE.State01; 
             break;
         }
     }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Downstream · Mar 26, 2016 at 07:59 PM
@CasperLIHongKong Renderer.material.mainTexture can be used to change it, I believe. See the documentation on materials and shaders if it doesn't work.
Your answer
 
             Follow this Question
Related Questions
Need help getting reload animation in fps game that I'm making. 0 Answers
When animation end play reverse 0 Answers
Problem with Animation How to Move Property 0 Answers
I need Function to be in other script 1 Answer
Animation only plays once 0 Answers