public void setAlpha(float alpha) { MeshRenderer[] children = GetComponentsInChildren <MeshRenderer>(); Color newColor; foreach (MeshRenderer child in children) { newColor = child.material.color; newColor.a = alpha; child.material.color = newColor; if (alpha == 1f) { MaterialExtensions.ToOpaqueMode(child.material); } else { MaterialExtensions.ToFadeMode(child.material); } } }
/// <summary> /// shows / hides the classes game objects /// </summary> /// <param name="show">if true objs are shown, otherwise hidden</param> /// <param name="alpha">optional transpaceny</param> public void SetVisibility(bool show, float alpha = 1) { _visible = show; List <GameObject> models = new List <GameObject>(WheelchairModels); foreach (var model in models) { if (model != null) { model.SetActive(show); } } models.Add(UpperBody); models.Add(Legs); // if BioIK is needed for real roboy, only the meshes might need to be disabled, but for now just disable it all foreach (var obj in models) { if (obj == null) { continue; } foreach (var r in obj.GetComponentsInChildren <Renderer>()) { r.enabled = show; if (alpha < 1) { MaterialExtensions.ToFadeMode(r.material); } else { MaterialExtensions.ToOpaqueMode(r.material); } Color color = r.material.color; color.a = alpha; r.material.color = color; } } }
public void SetMaterialRenderingModeToTransparent() { MaterialExtensions.ToFadeMode(tree); matcolor.a = 0.25f; tree.color = matcolor; }