You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.0 KiB

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<RawImage>();
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.SetFloat("_LightPositionY", LightPositionY);
material.SetColor("_TopColor", TopColor);
material.SetColor("_BottomColor", BottomColor);
}
}
else
{
Debug.LogError("Material not assigned!");
rawImage = GetComponent<RawImage>();
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);
}
}
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);
}
}
}