using System.Collections; using System.Collections.Generic; using UnityEngine; namespace LuxWater { public class LuxWater_Projector : MonoBehaviour { public enum ProjectorType { FoamProjector, NormalProjector }; [Space(8)] public ProjectorType Type = ProjectorType.FoamProjector; [System.NonSerialized] public static List FoamProjectors = new List(); [System.NonSerialized] public static List NormalProjectors = new List(); // These varaiables must be public as they are accesses by the LuxWater_WaterProjectors - but we do not have to see them nor do we have to serialize them. [System.NonSerialized] public Renderer m_Rend; [System.NonSerialized] public Material m_Mat; private bool added = false; private Vector3 origPos; void Update () { var pos = transform.position; pos.y = origPos.y; // this.transform.position = pos; } // Use this for initialization void OnEnable () { origPos = transform.position; var rend = GetComponent(); if (rend != null) { m_Rend = GetComponent(); m_Mat = m_Rend.sharedMaterials[0]; m_Rend.enabled = false; if (Type == ProjectorType.FoamProjector) FoamProjectors.Add(this); else NormalProjectors.Add(this); added = true; } } // Update is called once per frame void OnDisable () { if (added) { if (Type == ProjectorType.FoamProjector) FoamProjectors.Remove(this); else NormalProjectors.Remove(this); m_Rend.enabled = true; } } } }