Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize alarm Lamp in Unity3D

Shulou Source: shulou.com Published: 2022-06-03 05:04:24 10月04日 Update

Today, I will talk to you about how to realize the alarm light in Unity3D. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

Function description: the role enters a dangerous state and triggers the alarm light. The light turns on, gradually brightens, the brightness reaches the maximum, and gradually darkens. The character is out of danger and the alarm light is turned off. At the same time trigger the alarm music on and off.

1. First add an alarm light to the scene. (Alarm Light) 2. Set up its Transfrom,Tag and so on. 3. It is not enabled by default, and the invite value is 0. 0. The color is generally dark red RGB (70pl 0pl 0). 4.Culling Mask is Everying, does not participate in baking, Mode is Realtime.

Add a script:

Public float fadeSpeed=2f; / / Light Luminance gradient Speed public float highIntensity=4f; / / Luminance maximum public float highIntensity=0f; / / Luminance minimum public float changeMargin=0.2f; / / Mark for changing target brightness public bool alarmOn; / / whether or not alarm light is turned on private float targetIntensity; / / target brightness, toward the changed brightness private Light alarmLight; / / alarm light object void Awake () {alarmLight=GetComponent (); alarmLight.intensity=0; / / initial measurement is 0 targetIntensity=highIntensity / / Target is maximum luminance} / / Toggle target luminance void ChangeTargetIntensity () {if (Mathf.Abs (targetIntensity-alarmLight.intensity))

Tags: Brightness alarm alarm light target maximum maximum minimum content script change danger light character code function at the same time scene object time dark red Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple Shulou Tech Info MySQL vpn