54 lines
1.3 KiB
C#
Raw Normal View History

2025-08-09 17:43:37 +04:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Polyart
{
public class Cull_Lights : MonoBehaviour
{
[SerializeField] private float lightCullDistance;
[SerializeField] private float shadowCullDistance;
[SerializeField] private bool shadowsEnabled;
[SerializeField] private GameObject playerController;
private Light lightSource;
private void Awake()
{
lightSource = gameObject.GetComponent<Light>();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float playerDistance = Vector3.Distance(playerController.transform.position, gameObject.transform.position);
if (playerDistance <= lightCullDistance)
{
lightSource.enabled = true;
if (playerDistance <= shadowCullDistance && shadowsEnabled == true)
{
lightSource.shadows = LightShadows.Soft;
}
else
{
lightSource.shadows = LightShadows.None;
}
}
else
{
lightSource.enabled = false;
}
}
}
}