using System.Collections; using System.Collections.Generic; using UnityEngine; public class LightBulbEmissionUpdate : MonoBehaviour { [SerializeField] private Renderer _lightRend; [SerializeField] private float _intensity; [SerializeField] private Color _emissionColorValue; //[SerializeField] private Color _newEmissionColourValue; public bool UpdateEmission = true; public bool IsFlickering; private Color _emissionColorValueDefault; private float _intensityDefault; //public bool EmissionIsOn; //private bool _updateEmission; Animator _lightAnimator; private void Awake() { _lightAnimator = GetComponent(); _emissionColorValue = _lightRend.material.GetColor("_EmissionColor"); } // Start is called before the first frame update void Start() { _emissionColorValueDefault = _emissionColorValue; _intensityDefault = _intensity; if (IsFlickering) { LightIsFlickering(); } else { LightIsNotFlickering(); } } // Update is called once per frame void Update() { if (UpdateEmission) { //_lightRend.material.SetVector("_EmissionColor", _emissionColorValue * _intensity); var NewIntensity = (_emissionColorValue.r + _emissionColorValue.g + _emissionColorValue.b) / _intensity; var factor = /*( Mathf.Round*/(3.274745f / NewIntensity)/*)*/; _emissionColorValue = new Color (_emissionColorValue.r * factor, _emissionColorValue.g * factor, _emissionColorValue.b * factor, _emissionColorValue.a); _lightRend.material.SetVector("_EmissionColor", _emissionColorValue); } } public void EmissionIsEnabled() { _lightRend.material.EnableKeyword("_EMISSION"); } public void EmissionIsDisabled() { _lightRend.material.DisableKeyword("_EMISSION"); } public void ResetEmission() { _emissionColorValue = _emissionColorValueDefault; _intensity = _intensityDefault; } void LightIsFlickering() { _lightAnimator.SetBool("IsFlickering", true); } void LightIsNotFlickering() { _lightAnimator.SetBool("IsFlickering", false); ResetEmission(); } }