0 votes

I want my flashlight to be like:

On = losing battery life
Off = stop losing battery life

PLS Help

Godot version 3.5
in Engine by (22 points)

1 Answer

+2 votes
Best answer

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.

by (2,017 points)
selected by
Thanks bother
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.