- Home /
 
 
               Question by 
               afsoft · Feb 28, 2017 at 07:33 AM · 
                buttonmaterialchangechange material  
              
 
              Change material with UI button ?
Hello every one, i am really new to unity, so please go easy on me. i have a cube in the scene. plus i have a UI button. i expect when i press the button in game mode, the material changes to another. i have looked up the tutorial section, but my problem is that i dont know how to interact this script with the cube in the scene :
         using UnityEngine;
             using System.Collections;
             public class material_changer : MonoBehaviour {
         public Material [] material;
         Renderer rend;
         void Start () {
         rend = GetComponent<Renderer>();
         rend.enabled = true;
         rend.sharedMaterial = material [0];
         }
         
         // Update is called once per frame
 
         void OnClick () {
 
     }
 }
 
               i only know when this is dragged on the cube, the material will be the first material assigned. so how exactly should i get it to work? any idea ? also if some one could help me what does tagging system do, it will be great. thanks for reading.
               Comment
              
 
               
              Solved ! just dragging the cube on the Click event (in the button) and choosing $$anonymous$$ershRenderer.Shared$$anonymous$$aterial did it :)
Your answer