Files
grass-cutters/Assets/Scripts/Gameplay/Lamppost.cs
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

44 lines
1.6 KiB
C#

using UnityEngine;
namespace GrassCutter
{
/// <summary>A lamp post that comes on as the light goes: its glass glows and it throws a warm pool round its foot.</summary>
public class Lamppost : MonoBehaviour
{
public Renderer glow;
Light _light;
MaterialPropertyBlock _mpb;
float _on = -1f;
static readonly int EmissionId = Shader.PropertyToID("_EmissionColor"), BaseId = Shader.PropertyToID("_BaseColor");
static readonly Color Warm = new Color(1f, 0.78f, 0.45f);
void Start()
{
var go = new GameObject("Light");
go.transform.SetParent(transform, false);
go.transform.localPosition = new Vector3(0f, 2.35f, 0f);
_light = go.AddComponent<Light>();
_light.type = LightType.Point;
_light.color = Warm;
_light.range = 9f;
_light.shadows = LightShadows.None;
_mpb = new MaterialPropertyBlock();
}
void Update()
{
// lit a little before it's properly dark, out a little after the sun is up
float on = Mathf.Clamp01(DayNight.Dark * 1.6f + DayNight.Dusk * 0.6f);
if (Mathf.Abs(on - _on) < 0.02f) return;
_on = on;
_light.enabled = on > 0.05f;
_light.intensity = on * 2.2f;
if (!glow) return;
glow.GetPropertyBlock(_mpb);
_mpb.SetColor(EmissionId, Warm * (0.2f + on * 3f));
_mpb.SetColor(BaseId, Color.Lerp(new Color(0.85f, 0.82f, 0.7f), Warm, on));
glow.SetPropertyBlock(_mpb);
}
}
}