0

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.

Qstz D
  • 3
  • 3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – itprorh66 Mar 30 '22 at 21:04

1 Answers1

0

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.

pokepetter
  • 1,383
  • 5
  • 8