I want to create a flashlight, when you press 1 beam appears, but I want it to disappear after a second. I made it, but my code doesn't work. My code:
from ursina import *
app = Ursina()
def flashlight(): # flashlight code
f = Entity(model='sphere', scale=4, color=color.light_gray)
time.sleep(1.0) #pause
f.visible = False #disappearing
def update():
if held_keys['1']: flashlight()
app.run()```
To make the Entity
appear and disappear after 1 second, you can use Ursina' invoke function. Here is its implementation in your code:
from ursina import *
app = Ursina()
def test_func(e):
e.visible = False
def flashlight(): # flashlight code
f = Entity(model='sphere', scale=4, color=color.azure)
invoke(test_func, f, delay=.2)
def update():
if held_keys['1']: flashlight()
EditorCamera()
app.run()