How to add Flashlight life in godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By iAbrees

I want my flashlight to be like:

On = losing battery life
Off = stop losing battery life

PLS Help

:bust_in_silhouette: Reply From: magicalogic

Add a script to your spotlight and add this code.

extends SpotLight

var battery_amount = 100
var drain_rate = 2 
var on = true

func _process(delta):
    if on:
        battery_amount -= drain_rate * delta
    light_energy = battery_amount  / 100

drain_rate is how fast the battery drains.
You can turn on or of the flashlight by setting the on variable to true or false.

Thanks bother

iAbrees | 2022-12-27 15:08