using System.Collections; using System.Collections.Generic; using Unity.Mathematics; using UnityEngine; using UnityEngine.UI; public class SetLightStrength : MonoBehaviour { public float GradientEnd = 0.5f; public float LightPositionY = 1.2f; public Color TopColor = new Color(1f, 1f, 1f, 1f); public Color BottomColor = new Color(0f, 0f, 0f, 0f); RawImage rawImage; Material material; // Start is called before the first frame update void Start() { rawImage = GetComponent(); if (rawImage != null) { material = rawImage.material; } else { Debug.LogError("RawImage component not found on this GameObject."); } } // Update is called once per frame void Update() { if (material != null) { if (material != null) { material.SetFloat("_GradientEnd", GradientEnd); material.SetVector("_LightPosition", new float4(0.5f, LightPositionY, 0f, 0f)); material.SetColor("_TopColor", TopColor); material.SetColor("_BottomColor", BottomColor); } } else { Debug.LogError("Material not assigned!"); rawImage = GetComponent(); if (rawImage != null) { material = rawImage.material; } else { Debug.LogError("RawImage component not found on this GameObject."); } } } public void setStrength(float strength) { if (material != null) { material.SetFloat("_Strength", strength); material.SetFloat("_AlphaCutoff", Mathf.Clamp01(strength)); } } public void onReceiveStrength(string strength) { Debug.Log("Received strength: " + strength); if (float.TryParse(strength, out float result)) { // setStrength(Mathf.Lerp(material.GetFloat("_Strength"), result, Time.deltaTime * 5f)); setStrength(result); } } }