using System.Collections.Generic; using BitStrap; using UnityEngine; public class RefreshIceFishing : MonoBehaviour { public bool activeNormal = true; public bool activeIce = true; public Material materialNormal; public Material materialIce; public int materialID; public List materialsNormal = new List(); public List materialsIce = new List(); public bool updateSnow; public void Start() { if (GameController.Instance == null) { return; } bool iceLevel = GameController.Instance.iceLevel; base.gameObject.SetActive((iceLevel && activeIce) || (!iceLevel && activeNormal)); if (iceLevel && !activeIce) { Object.DestroyImmediate(base.gameObject, true); return; } if (!iceLevel && !activeNormal) { Object.DestroyImmediate(base.gameObject, true); return; } MeshRenderer[] componentsInChildren = GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { if (!iceLevel && (bool)materialNormal) { if (materialID == 0) { componentsInChildren[i].material = materialNormal; } else { componentsInChildren[i].materials[materialID] = materialNormal; } } else if (iceLevel && (bool)materialIce) { if (materialID == 0) { componentsInChildren[i].material = materialIce; } else { componentsInChildren[i].materials[materialID] = materialIce; } } } if (updateSnow && GetComponent().material.HasProperty("_Snow")) { GetComponent().material.SetFloat("_Snow", (!iceLevel) ? 0f : 1f); } } [Button] public void SetIceMaterials() { MeshRenderer[] componentsInChildren = GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { if (materialID == 0) { componentsInChildren[i].material = materialIce; } else { componentsInChildren[i].materials[materialID] = materialIce; } } } }