Could you please give an example of toggling between 2 materials of the target game object without disabling it ?
This is what i have so far but i get compile errors:
An object reference is required to access non-static member `CheckBoxMaterialToggle.material1
An object reference is required to access non-static member `CheckBoxMaterialToggle.material2
any help is greatly appreciated.
using UnityEngine;
using System.Collections;
public class CheckBoxMaterialToggle : MonoBehaviour {
public GameObject target;
public bool inverse = false;
public Material material1;
public Material material2;
static public void ChangeMaterial (GameObject target, bool state)
{
if (state)
target.renderer.material = material1;
else
target.renderer.material = material2;
}
void OnEnable ()
{
UICheckbox chk = GetComponent<UICheckbox>();
if (chk != null) OnActivate(chk.isChecked);
}
void OnActivate (bool isActive)
{
if (target != null) {
ChangeMaterial(target, inverse ? !isActive : isActive);
UIPanel panel = NGUITools.FindInParents<UIPanel> (target);
if (panel != null)
panel.Refresh ();
}
}
}