'How do I make the second entity disappear after remapping it
I have a small game I'm working on and I made it so when you aim the gun changes spots and is more centered but when I do that, the first image of a gun is still there.
Here is the code:
gun1 = True
if gun1 == True:
gun1 = Entity(model="assets/gun.obj", parent=camera.ui, scale=.03, color=rgb(0, 0, 139), position=(.5, -.7),
rotation=(-5, 5, 1))
if gun1 == False:
gun1 = Entity(model="assets/gun.obj", parent=camera.ui, scale=.03, color=rgb(0, 0, 139), position=(20, 20),
rotation=(-5, 5, 1))
def input(key):
if key == 'escape':
quit()
if key == "left mouse down":
Audio("assets/GunShot.mp3")
Animation("assets/spark", parent=camera.ui, fps=5, scale=.1, position=(.34, -.19), loop=False)
if key == "right mouse down":
gun2 = Entity(model="assets/gun.obj", parent=camera.ui, scale=.03, color=rgb(0, 0, 139), position=(.00, -.726),
rotation=(-5, 1, -1))
gun1 == False
You can see at the end it says 'gun1 == False' and I thought that should make the first one disappear but it doesn't.
Solution 1:[1]
When you do gun1 == False
, you overwrite the variable and it no longer refers to the Entity you created. I imagine what you want to is check gun_1.enabled
and set gun_1.enabled
and gun_2.enabled
to either True or False based on that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | pokepetter |