the torch light intensity will decreasing by time
attached this code to your torch gameobject
using UnityEngine;
public class LightDimmer : MonoBehaviour
{
public Light pointLight;
public float decreaseRate = 0.1f; // 0.1 intensity per second
void Update()
{
if (pointLight != null && pointLight.intensity > 0)
{
pointLight.intensity -= decreaseRate * Time.deltaTime;
pointLight.range = pointLight.intensity * 15/100;
pointLight.intensity = Mathf.Max(pointLight.intensity, 0); // Clamp to 0
}
}
}
add sphere to your scene
using UnityEngine;
public class CollectLight : MonoBehaviour
{
public Light torch;
// Start is called once before the first execution of Update after the MonoBehaviour is created
public void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
torch.intensity += 0.5f;
torch.range = torch.intensity *15/100;
Destroy(gameObject);
}
}
}