-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlighthouse.cs
More file actions
31 lines (24 loc) · 834 Bytes
/
lighthouse.cs
File metadata and controls
31 lines (24 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class Lighthouse2D : MonoBehaviour
{
[Header("Components")]
public Light2D lightSource;
[Header("Intensity Pulse")]
public float minIntensity = 0.5f;
public float maxIntensity = 2.5f;
public float pulseSpeed = 3.0f;
[Header("Movement")]
public float rotationSpeed = 100f;
void Update()
{
if (lightSource == null) return;
// Calculate smooth pulse using Sine
// Maps -1 to 1 range into a 0 to 1 range
float wave = (Mathf.Sin(Time.time * pulseSpeed) + 1f) / 2f;
// Apply intensity
lightSource.intensity = Mathf.Lerp(minIntensity, maxIntensity, wave);
// Optional: Rotate the light object
transform.Rotate(0, 0, rotationSpeed * Time.deltaTime);
}
}