I see two issues here. First of all, the code is not properly indented and is not valid Python.
The second issue is that you're creating a new Text every time you press a key. It's better to create it once, outside of the function and just set .text
to update it.
You're also resetting all_ammo
and round_ammo
to 100 each time you press a key. Again, this should be set outside of the input function so it doesn't get reset every time you press a key.
Example:
from ursina import *
app = Ursina()
gun = Entity(ammo=10) # use this to store the variable so we don't have to use the global keyword
text_entity = Text(text=f'ammo: {gun.ammo}')
def input(key):
if key == 'left mouse down':
gun.ammo -= 1
text_entity.text = f'ammo: {gun.ammo}'
app.run()