// LightControl.cs using System.Collections; using Simuspaces.Simulation; public class LightControl : SimuScriptBase { public SceneObject ClickObject; public SVLight ControlledLight; public float tickSeconds = 0.25f; public bool highlightObject = true; public float interactDistance = 10f; bool animating; Coroutine lightLoop; public override void Start() { if (ClickObject == null || ClickObject.IsNull) { Log("[LightControl] Slot a SceneObject into ClickObject first."); return; } if (ControlledLight == null || ControlledLight.IsNull) { Log("[LightControl] Slot a Light into ControlledLight first."); return; } MakeInteractable( ClickObject, OnClicked, highlightObject, null, true, interactDistance, "Toggle light"); Log("[LightControl] Interactable registered on " + ClickObject.ObjectId); } void OnClicked(SVInteractionInfo info) { animating = !animating; if (animating) { SetLightEnabled(ControlledLight, true); lightLoop = StartCoroutine(AnimateLight()); } else { if (lightLoop != null) StopCoroutine(lightLoop); SetLightEnabled(ControlledLight, true); SetLightIntensity(ControlledLight, 1f); SetLightColor(ControlledLight, Color.white); SetLocalRotation(ControlledLight, new Vector3(0f, 0f, 0f)); } Log("[LightControl] " + info.Username + " clicked " + info.ObjectName + " animating=" + animating); } IEnumerator AnimateLight() { while (animating) { float t = Mathf.PingPong(Time.time, 1f); SetLightIntensity(ControlledLight, Mathf.Lerp(0.5f, 3f, t)); SetLightColor(ControlledLight, Color.Lerp(Color.red, Color.cyan, t)); SetLocalRotation(ControlledLight, new Vector3(45f, Time.time * 45f, 0f)); yield return new WaitForSeconds(tickSeconds); } } }